With over 52,000 stars and 520+ contributors, LocalStack is an open-source tool that emulates a wide range of AWS services on a local machine. It's primarily used for testing and development purposes, allowing developers to run applications locally without needing to interact with the actual AWS cloud.
LocalStack is a cloud development platform that solves the challenge of costly and slow cloud resource usage during development and testing of serverless applications. By providing a local environment that replicates AWS services, LocalStack helps developers ensure that their applications work correctly before deploying them to a live environment.
Key features of LocalStack include:
- Service Emulation: It emulates various AWS services such as S3, DynamoDB, Lambda, API Gateway, SQS, SNS, CloudFormation, and more.
- Local Development: Developers can run AWS services locally, which speeds up development cycles and reduces costs associated with using AWS resources.
- Consistency: Ensures that the development environment closely mirrors the production environment on AWS, reducing discrepancies and potential issues during deployment.
- Automation and CI/CD Integration: LocalStack can be integrated into CI/CD pipelines, enabling automated testing of AWS-dependent code.
- LocalStack can be run using Docker, making it easy to set up and use on various platforms.
Benefits of using Localstack:
- Reduced Costs: By emulating AWS services locally, LocalStack eliminates the need to constantly deploy to the cloud, saving you money on cloud charges.
- Faster Development: LocalStack lets you spin up services instantly on your machine, significantly speeding up development cycles compared to waiting for cloud deployments.
Getting Started
You can directly start the LocalStack container using the Docker CLI. This method requires more manual steps and configuration, but it gives you more control over the container settings.
The first time you start localstack, it requires Docker daemon to be up and running on your system.
localstack start -d
__ _______ __ __
/ / ____ _________ _/ / ___// /_____ ______/ /__
/ / / __ \/ ___/ __ `/ /\__ \/ __/ __ `/ ___/ //_/
/ /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,<
/_____/\____/\___/\__,_/_//____/\__/\__,_/\___/_/|_|
๐ป LocalStack CLI 3.5.0
๐ค Profile: default
[09:22:54] starting LocalStack in Docker mode ๐ณ localstack.py:503
preparing environment bootstrap.py:1283
ERROR: '['docker', 'ps']': exit code 1; output: b'Cannot connect to the Docker daemon at unix:///Users/ajeetsraina/.docker/run/docker.sock. Is the docker daemon running?\n'
โ Error: Docker could not be found on the system.
Please make sure that you have a working docker environment on your machine.
Install Docker Desktop on your system and now this time you will find that Localstack gets started successfully.
localstack start -d
__ _______ __ __
/ / ____ _________ _/ / ___// /_____ ______/ /__
/ / / __ \/ ___/ __ `/ /\__ \/ __/ __ `/ ___/ //_/
/ /___/ /_/ / /__/ /_/ / /___/ / /_/ /_/ / /__/ ,<
/_____/\____/\___/\__,_/_//____/\__/\__,_/\___/_/|_|
๐ป LocalStack CLI 3.5.0
๐ค Profile: default
[09:23:54] starting LocalStack in Docker mode ๐ณ localstack.py:503
preparing environment bootstrap.py:1283
configuring container bootstrap.py:1291
starting container bootstrap.py:1301
[09:23:55] detaching bootstrap.py:1305
You can also start the Docker container simply by executing the following docker run command:
$ docker run --rm -it -p 4566:4566 -p 4510-4559:4510-4559 localstack/localstack
List of AWS services that Localstack support
localstack status services
โโโโโโโโโโโโโโโโโโโโโโโโโโโโณโโโโโโโโโโโโโโ
โ Service โ Status โ
โกโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฉ
โ acm โ โ available โ
โ apigateway โ โ available โ
โ cloudformation โ โ available โ
โ cloudwatch โ โ available โ
โ config โ โ available โ
โ dynamodb โ โ available โ
โ dynamodbstreams โ โ available โ
โ ec2 โ โ available โ
โ es โ โ available โ
โ events โ โ available โ
โ firehose โ โ available โ
โ iam โ โ available โ
โ kinesis โ โ available โ
โ kms โ โ available โ
โ lambda โ โ available โ
โ logs โ โ available โ
โ opensearch โ โ available โ
โ redshift โ โ available โ
โ resource-groups โ โ available โ
โ resourcegroupstaggingapi โ โ available โ
โ route53 โ โ available โ
โ route53resolver โ โ available โ
โ s3 โ โ available โ
โ s3control โ โ available โ
โ scheduler โ โ available โ
โ secretsmanager โ โ available โ
โ ses โ โ available โ
โ sns โ โ available โ
โ sqs โ โ available โ
โ ssm โ โ available โ
โ stepfunctions โ โ available โ
โ sts โ โ available โ
โ support โ โ available โ
โ swf โ โ available โ
โ transcribe โ โ available โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโ
Creating a AWS S3 Bucket
Create an s3 bucket with LocalStack's awslocal CLI:
awslocal s3api create-bucket --bucket sample-bucket
{
"Location": "/sample-bucket"
}
Listing the S3 Bucket
awslocal s3api list-buckets
{
"Buckets": [
{
"Name": "sample-bucket",
"CreationDate": "2024-06-29T17:56:46.000Z"
}
],
"Owner": {
"DisplayName": "webfile",
"ID": "75aa57f09aa0c8caeab4f8c24e99d10f8e7faeebf76c078efc7c6caea54ba06a"
}
}
Listingthe items inside the bucket:
awslocal s3api list-objects --bucket sample-bucket
{
"RequestCharged": null
}
Running Localstack using Docker Compose
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}"
image: localstack/localstack
ports:
- "127.0.0.1:4566:4566" # LocalStack Gateway
- "127.0.0.1:4510-4559:4510-4559" # external services port range
environment:
# LocalStack configuration: https://docs.localstack.cloud/references/configuration/
- DEBUG=${DEBUG:-0}
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"
Starting the container
docker compose up
[+] Running 1/0
โ Container localstack_demo Recreated 0.1s
Attaching to localstack-main
localstack-main |
localstack-main | LocalStack version: 3.5.1.dev
localstack-main | LocalStack build date: 2024-06-24
localstack-main | LocalStack build git hash: 9a3d238ac
localstack-main |
localstack-main | Ready.
Creating a queue using SQS with LocalStack's awslocal CLI:
$ awslocal sqs create-queue --queue-name test-queue
Result:
{
"QueueUrl": "http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/test-queue"
}
$ awslocal sqs list-queues
Result:
{
"QueueUrls": [
"http://sqs.us-east-1.localhost.localstack.cloud:4566/000000000000/test-queue"
]
}
Top comments (0)