This document discusses using the Serverless Application Model (SAM) to develop serverless applications locally. It describes how SAM templates allow defining Lambda functions and APIs that can then be run locally using the SAM CLI. This avoids needing an internet connection to test functions and allows using local tools like debuggers. Examples are provided for local development workflows involving APIs, Lambda functions, DynamoDB, and S3 event processing. Key links are also provided to learn more about SAM templates, the SAM CLI, and running DynamoDB locally.
2. OFF THE CLOUD
• Problem: We love lambdas in the cloud to a failing.
• Symptoms:
• Our favorite debugging tools are on our laptops
• Local integration testing is easier than on the cloud
• We have to meet a sprint deadline and are coding on our laptops during a long cross country flight without
internet access to meet that deadline
• You are on a NASA space station and are preparing for your AWS Certification Exam without internet access
@spicykey
6. WHY IS THIS HARD
• Software Prerequisites
• Go
• Docker
• AWS command line tools
• AWS SAM local tools
• A debugger that can easily connect to a remote process by port
• IAM Prerequisites
• A profile with IAM rights on your laptop
• Configuration
• Docker networks
• Capturing lambda logs locally
• Must learn template language and write templates by hand
@spicykey
7. LOCAL DYNAMODB + LOCAL LAMBDA
• Run DynamoDB on your laptop, http://localhost:8000
• Use Docker 18.3+ on a Mac OS X or Windows laptop for easy Docker Network routing to the host
(http://host.docker.internal:8000)
• Route the lambda function’s dynamodb client to your laptop’s DynamoDB endpoint (javascript/nodejs
example)
• const dynamodb = new AWS.DynamoDB({endpoint: 'http://host.docker.internal:8000'});
@spicykey
10. SCENARIO – S3 EVENT DEVELOPMENT
• Example: A developer has a javascript based lambda function that responds to S3 events that is buggy.
The developer creates a project in visual studio for the lambda function. The developer then creates a
SAM template for the function. First, the developer runs visual studio and sets a breakpoint. Then,
invokes the function with ‘sam local invoke –d 5858.’
@spicykey
11. THREE IMPORTANT LINKS
• Serverless Application Model (SAM) Templates - https://github.com/awslabs/serverless-application-
model
• SAM Local Command Line Interface (CLI) - https://github.com/awslabs/aws-sam-local
• Local DynamoDB -
https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
@spicykey
12. THANK YOU – ABOUT ME
• #Serverless
• #Alexa
• #Code
@spicykey
SpicyKey LLC develops apps for clients
https://spicykey.com https://youtube.com/spicykey