Skip to content

aws-samples/enable-lambda-snapstart-with-iac-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

How to Enable Lambda Snapstart with AWS Cloudformation, AWS SAM, AWS CDK and Terraform

This Sample Code repository demonstrates how to enable Lambda SnapStart with AWS Cloudformation, AWS SAM, AWS CDK and Terraform.

For each IaC tooling, you will find 2 templates: one without SnapStart and one with SnapStart. Each template is configured with the same architecture: an API Gateway, a Lambda Function and a DynamoDB table, and all the examples leverage the same Lambda Function code, which you can find under code/UnicornStockLambda/.
This allows you to compare and contrast the differences between different implementations.

How to use this repository

All the code in this repository can be deployed to your own AWS Account. Please note that you may incur cost when deploying the resources.

Build the sample application

Before deploying the Sample, ensure that the application successfully builds

cd code/UnicornStockLambda
mvn clean package

Deploy the sample

AWS Cloudformation (without SnapStart)

BUCKET_NAME=<<YOUR BUCKET NAME>>
FUNCTION_KEY=<<SAMPLE KEY>>
aws s3 cp code/UnicornStockLambda/target/UnicornStockBroker-1.0-aws.jar s3://$BUCKET_NAME/$FUNCTION_KEY
cd code/cloudformation
aws cloudformation deploy --template-file ./template.yaml --stack-name UnicornBrokerWithoutSnapStart --capabilities CAPABILITY_NAMED_IAM --parameter-overrides FunctionSourceCodeBucketName=$BUCKET_NAME FunctionSourceCodeKey=$FUNCTION_KEY

AWS Cloudformation (With SnapStart)

BUCKET_NAME=<<YOUR BUCKET NAME>>
FUNCTION_KEY=<<SAMPLE KEY>>
aws s3 cp code/UnicornStockLambda/target/UnicornStockBroker-1.0-aws.jar s3://$BUCKET_NAME/$FUNCTION_KEY
cd code/cloudformation
aws cloudformation deploy --template-file ./template-with-snapstart.yaml --stack-name UnicornBrokerWithSnapStart --capabilities CAPABILITY_NAMED_IAM --parameter-overrides FunctionSourceCodeBucketName=$BUCKET_NAME FunctionSourceCodeKey=$FUNCTION_KEY

AWS SAM (without SnapStart)

cd code/sam
sam build  -t template.yaml 
sam deploy --guided -t template.yaml

AWS SAM (with SnapStart)

cd code/sam
sam build -t template-with-snapstart.yaml 
sam deploy -t template-with-snapstart.yaml --guided

Terraform (without SnapStart)

cd code/terraform/without-snapstart/
terraform apply

Terraform (with SnapStart)

cd code/terraform/with-snapstart/
terraform apply

CDK (without SnapStart)

cd code/cdk/without-snapstart/
mvn clean package
cdk deploy

CDK (with SnapStart)

cd code/cdk/with-snapstart/
mvn clean package
cdk deploy

Test the application

After deploying the application, you can invoke it with the following commands:

export API_GW_URL="YOUR API GATEWAY URL HERE"
curl -XPOST "$API_GW_URL/transactions" --data '{"stockId":"UNICORN_STOCK", "quantity":"2"}' --header 'Content-Type: application/json'

Security

See CONTRIBUTING for more information.

License

This library is licensed under the MIT-0 License. See the LICENSE file.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published