‫The first thing I have to do is to go to
‫commands and I will basically create an s3 bucket.
‫For this we know the command line now is aws s3 make bucket
‫and I will just say stephane-code-sam.
‫Should be a unique name, obviously,
‫you need to change the s3 bucket to a name you have.
‫I have a terminal right here so I'll just go ahead
‫and paste this aws s3 make bucket and now we have made
‫my bucket stephane-code-sam.
‫If I go to my s3 and refresh now we see there is
‫stephane-code-sam as a bucket that was created
‫and now it's empty.
‫So we need to start uploading code and so
‫the first thing you want to do is
‫package our cloudformation and so
‫for this we will do aws cloudformation package
‫and we will have to specify the right parameters.
‫So let's do this function, cloudformation package,
‫press enter and we'll do help to get some information
‫around what we should be doing.
‫If you scroll down, we see that we have to specify
‫the s3 bucket we're in so we'll say
‫s3 bucket is stephane-code-sam, okay.
‫Then you need to specify the template file we have.
‫The template file we have is going to be template.yaml .
‫Then the output template file,
‫because we generate something,
‫is going to go under a gen directory.
‫I'm just going to have a gen directory
‫because we generate code, so I'll say gen
‫and here I will say template-generated.yaml.
‫This is going to be out transformed cloudformation template.
‫This looks about right, it looks like I have everything
‫I need for this function.
‫Let me go ahead and quit this and run our command line.
‫Press enter and it's successfully completed.
‫What it did, is that it actually uploaded code to s3.
‫It says successfully packaged artifacts and
‫wrote output template to the file
‫gen/template-generated file.
‫It says I need to execute the following command
‫to now deploy my code.
‫By the way, we could have run sam and package, the command.
‫It would have been exactly the same.
‫If sam is just a shorthand for aws cloudformation
‫when you use the package commands.
‫Okay, so we have the first thing done.
‫Let's look at this template-generated file just so
‫we can have a good look at it.
‫It looks just the same except now the CodeUri
‫is now referencing s3.
‫It turns out that my code was uploaded into s3 and
‫this CodeUri right here was automatically updated
‫to reference that s3 bucket and
‫that file that was updated.
‫This was the little nice thing done
‫by cloudformation package.
‫Obviously, you can do way more
‫but this is just a little taster.
‫Now let's go ahead and deploy and before that maybe
‫we should check in our bucket.
‫Indeed, yes, a file was uploaded.
‫Now we are going to deploy our template.
‫It says you should run this command,
‫aws cloudformation deploy, and then the template file is,
‫and you'll need the whole path.
‫I can just use gen/template-generated and the stack name
‫is going to be hello-world-sam.
‫That sounds about right.
‫I'm going to go ahead and run this command.
‫This will, basically, create a changeset.
‫It's waiting right now for the changeset to be created.
‫When it's ready it's going to do the changesets.
‫Here it says the changeset's generation has failed.
‫The reason is that it requires a CAPABILITY_IAM.
‫This is the annoying thing when you
‫do run this package command.
‫It doesn't necessarily give you the right answer
‫and the right commands.
‫You actually need to add a capability, flagged right here.
‫Here I am going to add capabilities and then I will
‫just copy this CAPABILITY_IAM because we are
‫generating an IAM role.
‫I will run this command again and now it's waiting
‫for the changeset to be created.
‫This time everything should be created just fine.
‫Now the stack is in create/update state.
‫Let's go to our cloudformation.
‫Let's go here and we can go to services, cloudformation,
‫and let's make sure I'm in the right region.
‫I'm in the Paris region.
‫This is where I configured my CLI to work.
‫Here, as we can see, the hello-world-sam
‫is in create in progress.
‫Automatically this cloudformation stack
‫was being created for me.
‫Now I just need to wait for the create to happen.
‫The create function has completed, as we can see.
‫If you look at the resources that were created,
‫as we can see, my helloworldpython Lambda function
‫was created, but also a
‫helloworldpython3 IAM role was created.
‫We had both a Lambda function and an IAM role
‫that was created for us.
‫We could look at the events.
‫I don't know where I'm getting this error.
‫We could look at the events to see what happened over time.
‫Now if we go to Lambda.
‫We'll just type Lambda right here.
‫We should be able to see our function
‫that was deployed here, this hello-world-sam
‫and it is managed by sam
‫and we get a generated name by a cloudformation.
‫If we look at the function code, as we expect,
‫it is the code we had in our local environment
‫which is returning as Hello World.
‫We could, obviously, go ahead and test that function.
‫Click on create, testevent, and now click on create,
‫and now click on test and our function
‫is really invoked and says Hello World.
‫This was very basic but overall,
‫we've just shown how we could write code on our computer.
‫How with two command lines only,
‫upload this directly to cloudformation,
‫and cloudformation to create the Lambda function for us.
‫Obviously, sam is way more powerful, so the next lecture
‫we're going to see how we can update this app
‫to do more things for us.
‫See you in the next lecture.