Localstack

I recently discovered Localstack, which is a local AWS Cloud. You can develop and test your cloud apps directly on your PC locally and offline. It’s pretty handy if you working in a team and each of them need his own S3/SNS/SQS etc..

Windows docker setup

The easiest way to deploy it locally is by running the localstack docker container.
To let the localstack docker run on Windows, is it required to adjust the docker-compose.yml slightly by:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
version: '2.1'

services:
localstack:
image: localstack/localstack
ports:
- "4567-4583:4567-4583"
- "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
environment:
- SERVICES=${SERVICES- }
- DEBUG=${DEBUG- }
- DATA_DIR=/tmp/localstack/data
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "localstack-vol:/tmp/localstack"
volumes:
localstack-vol:

If the docker container is running, it will expose all the services on a different port. You can check here, on which port which service is running.
To use it, the only change you need to do, is to pointing the AWS cli/sdk that you would like to use your local instance.
You do it by setting the endpoint url parameter.

AWS CLI Examples

S3

Create a bucket

1
aws --endpoint-url=http://localhost:4572 s3 mb s3://testbucket

Copy a file to S3

1
aws --endpoint-url=http://localhost:4572 s3 cp testfile.txt s3://testbucket

Download a file from S3

1
aws --endpoint-url=http://localhost:4572 s3 cp s3://testbucket/testfile.txt testfile.txt

SQS

Create a Queue

1
aws --endpoint-url=http://localhost:4576 sqs create-queue --queue-name testqueue

After creating a queue, you will get an unique queue name (queue-url) , which you need to send/receive messages.

Send a message to the queue

1
aws --endpoint-url=http://localhost:4576 sqs send-message --queue-url http://localhost:4576/queue/testqueue --message-body 'Test Message!'

Read/Receive a message from the queue

1
aws --endpoint-url=http://localhost:4576 sqs receive-message --queue-url http://localhost:4576/queue/testqueue