Serverless LocalStack Lambda.
Docker Compose LocalStack
In this article, We will show you how you can use docker-compose to create LocalStack services.
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
We hope you have installed Docker on your system else you can check the following article to install Docker.
Setting Up Docker and Kitematic MacOS/Windows
Installation/Setting Up Docker, Kitematic and VirtualBox MacOS/Windows
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.
- 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.
4. Install AWS Client
Make sure you have installed AWS client on your system if not you can follow the following link to install
Install AWS Client
In this article, We will show you how to set up the AWS client
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
All services will be accessed using http://localhost:4566 URL
Run the following command to run the docker container
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
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
Serverless LocalStack Lambda GitHub is home to over 50 million developers working together to host and review code…
Thank you! 🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀🚀