An AWS Lambda function using a Lambda layer

AWS Lambda

Create Lambda function with a Lambda layer

This sample project demonstrates how to deploy a Lambda Function that has a layer added to it.
The SAM template provided deploys two Lambda functions. Both Lambda functions attempt to import the PyMySQL package.
However, only one of the Lambda functions has the PyMySQL layer which allows it to import the package successfully.
This pattern tests both Lambda functions to illustrate the difference when there is a layer added to a Lambda function.
One use case for Lambda layers is to have packages like PyMySQL shared across various Lambda functions that require connections to RDS MySQL.
Using layers reduces the size of uploaded deployment archives and makes it faster to deploy your code.

< Back to all patterns

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/lambda-layer

Deploy

sam deploy


Testing

See the GitHub repo for detailed testing instructions.

Cleanup

Delete the stack: sam delete.

Created by:

Glenn Chia Jin Wee

Glenn Chia Jin Wee

Glenn is an Associate Cloud Architect at AWS based in Singapore

Follow on LinkedIn