Lambda
AWS Lambda is a Serverless Function as a Service (FaaS) system that allows you to write code in your favorite programming language and run it on the AWS ecosystem. Unlike deploying your code on a server, you can now break down your application into many independent functions and deploy them as a singular units. With the help of AWS Lambda, you can strive for more modular code that can be tested and debugged while integrated with the AWS infrastructure and your core system.
LocalStack allows you to execute your Lambda functions locally, without the need to deploy them to AWS. This is a great way to test your code, and to learn more about how your Lambda functions work, before deploying them to AWS. LocalStack allows you to execute your Lambda functions, in various execution modes, which is detailed on our Lambda execution modes page.
We also provide tools to help you develop, debug and test your Lambda functions more efficiently:
- : Hot code swapping for Lambda functions using LocalStack’s code mounting feature.
LocalStack Pro samples contains a number of code examples that demonstrate how to use LocalStack to execute Lambda functions:
- Lambda XRay Tracing: Simple demo application illustrating Lambda XRay tracing using LocalStack, deployed via the Serverless framework.
- : Simple demo application illustrating Lambda container images in LocalStack. The Lambda image is built using Docker and pushed to a local ECR registry.
- Lambda Code Mounting and Debugging: Simple demo application to illustrate debugging Lambdas locally.
Please make sure and python 2/3
is installed inside your container image for the integration with LocalStack to work.
are an AWS feature that allows to pull in additional code and content into your Lambda functions.
LocalStack Pro provides support for deploying Lambda layers locally - for more details on general usage, please follow the documentation and examples in the AWS documentation on Lambda layers.
To create a Lambda layer locally, you can simply use the API against LocalStack. Below is a simple example for creating a Lambda layer in Python with a util()
function that prints some test output.
Once we invoke the Lambda function, we should see the following logs in the LocalStack container (with enabled), which includes the output from the layer util function:
Referencing Lambda layers from real AWS
Alternatively, if your Lambda function references a layer in real AWS, there is also a mechanism to integrate such a remote layer into your local dev environment.
In order to achieve that, you’ll need to make your Lambda layer accessible from the 886468871268
AWS account ID (this is an account managed by LocalStack on AWS). Assuming you’ve created a layer named with version 1
, you can use the following command to grant access to your layer:
Next time you reference this layer (with the real AWS Lambda layer ARN) in one of your local Lambda functions, it will get automatically pulled down and integrated into your local dev environment.