This video will show you how to use AWS SAM to build, package and deploy an AWS Lambda written in Node 10.x
Rich Buggy: [00:00] To create a new project, I'll use the sam init command with the -r option to set the run time to nodejs10.x and -n to create it in a new folder called demo.
[00:14] Once the project is being created, I'll open it up in my editor. The template.yaml file contains the cloud formation configuration for my project. In the resources section, the default template includes one function called HelloWorld.
[00:32] The code for the handler for my function is located in the app.js file in the Hello World folder. To build the project, use sam build.
[00:49] Once you've build the application, you need to upload it to S3 for deployment using sam package command. The name of the S3 deployment bucket is set using the S3 bucket option.
[01:02] Sam package will create a version of your template.yaml file with the local files replaced with the S3 URLs. To save that, I will use the app with template option and call the output file, packaged.yaml. You also need to provide the name of the AWS profile and the region.
[01:25] Once the project has been packaged, you can deploy using the sam deploy command. For the template file option, you need to use to file that was created by sam package.
[01:36] In this example, I'll use the stack name option to name my stack demo. I also need to set capabilities to CAPABILITY_IAM. Finally, I need to set the AWS profile to use for deployment and the region to deploy it to.
[01:58] Once that project has being deployed, we can go a CloudFormation in the AWS Console and you'll see the new stack. Clicking on the stack name shows me the details for that particular stack. In the Events, you can see what happened during deployment. This is useful if something goes wrong and you need to debug the problem.
[02:19] In the Resources tab, you'll see the resources that were created in your AWS account during the creation of CloudFormation stack. Clicking on the physical ID next to HelloWorldFunction, will take me to the Lambda console for the HelloWorldFunction.
[02:35] You can see that the HelloWorldFunction is triggered by the API Gateway. If I click on API Gateway, I can then see the URL for the API endpoint that will trigger my Lambda. Clicking on this opens up the new window, and we can see the response from the Lambda, the message, "Hello World."