🎁

12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
15 : 05 : 59 : 06
Join egghead, unlock knowledge.

Want more egghead? It's 58% off for a limited time only!

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock All Content for 40% Off
1×
Become a member
to unlock all features
Autoplay

    Build, Package and Deploy Node 10.x Lambda using AWS SAM

    Rich BuggyRich Buggy
    awsAWS

    This video will show you how to use AWS SAM to build, package and deploy an AWS Lambda written in Node 10.x

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Discuss

    Discuss

    Transcript

    Transcript

    Rich Buggy: 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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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.

    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."