Serverless LocalStack Lambda
Serverless LocalStack Lambda.
In this article, we will help you to cover the Serverless framework with LocalStack to create Lambda function locally.

We hope you are familiar with the Serverless framework and LocalStack If you are not please read our previous article.
Video
What is LocalStack?
LocalStack provides an easy-to-use test/mocking framework for developing Cloud applications. This means you can test AWS cloud resources locally on your machine.
Note: LocalStack supporting only AWS cloud stack.
LocalStack spins up the following core Cloud APIs on your local machine.
- ACM, API Gateway, CloudFormation, CloudWatch
- CloudWatch Logs, DynamoDB, DynamoDB Streams
- EC2, Elasticsearch Service, EventBridge (CloudWatch Events)
- Firehose, IAM, Kinesis, KMS, Lambda, Redshift
- Route53, S3, SecretsManager, SES, SNS
- SQS, SSM, StepFunctions, STS
Benefits of Using LocalStack
- Reduce Cost
- Test AWS Cloud Resource Locally
- Learn AWS Cloud Resource Locally
- Debug Locally
Let’s Start
We hope you have installed Docker on your system else you can check the following article to install Docker.
Make Sure You have installed Node JS or NVM on your system or follow the following article.
Node.JS Installation Best Practise Mac OS
Best Practise Node.JS version manager.
onexlab-io.medium.com
- Install a serverless framework using the following command
npm install -g serverless
2. Install a serverless-localstack plugin using the following command
npm install --save-dev serverless-localstack
3. Create a new Serverless Service/Project
serverless create — template aws-nodejs — path localstack-lambda

Once the project created successfully. You will see the following files as shown in the screenshot.

- handler.js
2. serverless.yml
4. Install AWS Client
Make sure you have installed AWS client on your system if not you can follow the following link to install
5. Docker Compose file
Create a new file docker-compose.yml file under the root directory of the project as shown below.

In the above file, we are creating a LocalStack docker image with the following services
- Lambda
- S3
- Cloudformation
- STS
All services will be accessed using http://localhost:4566 URL
Run the following command to run the docker container
docker-compose up

Once the container started successfully you will see the logs of the LocalStack services as shown below

To check all the services type the following URL in the browser
http://localhost:4566/
You will see the defined services running fine as shown in the below screenshot

6. Now update the serverless.yml file to add the LocalStack plugin as shown below
In the above file, we have added the local/dev stage as well as endpointFile localstack_endpoints.json as shown below
Let’s deploy the serverless stack locally
To deploy the hello function in the LocalStack run the following command
serverless deploy --stage local
To check the service deployed successfully. Run the following command
serverless info --stage local
Then you will see the following output as shown below

To invoke the function locally. Run the following command
serverless invoke local -f hello -l
Then you will see the following output as shown below which means the function run successfully locally using LocalStack

Github
Thank you! 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀