What is LocalStack?
LocalStack is a tool that allows you to simulate AWS services in a local environment. You can test and develop resources like S3 and Lambda without using a cloud environment. This time, I'll demonstrate using CloudFormation to create an S3 bucket with LocalStack.
Running It Locally
Create a docker-compose.yml file with the following content:
version: '3.8'
services:
localstack:
image: localstack/localstack
ports:
- "4566:4566" # LocalStack unified endpoint
environment:
- SERVICES=cloudformation,s3,dynamodb # Specify services to enable as comma-separated values
- DEBUG=1 # Enable debug mode
Next, run the following command to start LocalStack:
$ docker-compose up -d
Deploying CloudFormation
Let me write a sample CloudFormation template:
AWSTemplateFormatVersion: '2010-09-09'
Resources:
MyBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: my-localstack-bucket
Now, let's deploy it to LocalStack:
$ aws --endpoint-url=http://localhost:4566 cloudformation create-stack --stack-name myteststack --template-body file://template.yml
{
"StackId": "arn:aws:cloudformation:ap-northeast-1:000000000000:stack/myteststack/8320a915"
}
Alert: Be careful to always specify the
--endpoint-urlparameter. Without it, the deployment will go to your production environment.
Verifying the Deployment
Let's verify that S3 was created successfully:
$ aws --endpoint-url=http://localhost:4566 s3 ls
2025-09-23 23:48:30 my-localstack-bucket
Thoughts
It's convenient to be able to create and test resources without touching the actual cloud environment. If you're developing with CloudFormation, incorporating LocalStack into your CI/CD pipeline could enable automated testing before deployment.
Top comments (0)