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.
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.
Before deploying the Sample, ensure that the application successfully builds
cd code/UnicornStockLambda
mvn clean packageBUCKET_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_KEYBUCKET_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_KEYcd code/sam
sam build -t template.yaml
sam deploy --guided -t template.yamlcd code/sam
sam build -t template-with-snapstart.yaml
sam deploy -t template-with-snapstart.yaml --guidedcd code/terraform/without-snapstart/
terraform applycd code/terraform/with-snapstart/
terraform applycd code/cdk/without-snapstart/
mvn clean package
cdk deploycd code/cdk/with-snapstart/
mvn clean package
cdk deployAfter 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'See CONTRIBUTING for more information.
This library is licensed under the MIT-0 License. See the LICENSE file.