If you use this example, you will have a AWS Localstack Docker instance running on your local environment. This will enable you to test AWS commands or applications without having an AWS account. All happens in your local environment.


Localstack


This is just a bare minimum example setup for the s3 service which runs on eu-west-1 region. If you get a "volume" related error, refer to the documentation. This works fine for Mac OS.


version: "2.1"

services:
localstack:
image: "localstack/localstack"
container_name: "localstack"
ports:
- "4566-4599:4566-4599"
environment:
- DEBUG=1
- DEFAULT_REGION=eu-west-1
- SERVICES=s3
- DATA_DIR=/tmp/localstack/data
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "/tmp/localstack:/tmp/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"

Once you run it, you should see container as shown below.


CONTAINER ID   IMAGE                   COMMAND                  PORTS                                        NAMES
600094dd55c1 localstack/localstack "docker-entrypoint.sh" 0.0.0.0:4566-4599->4566-4599/tcp, 8080/tcp localstack

Visiting http://localhost:4566 should produce {"status": "running"} response. All the enabled APIs (s3 in our case) are accessible via edge service port 4566.


AWS


Assuming that the aws cli is installed on your system. Create a custom profile dedicated to our Localstack setup.


$ aws configure --profile localstack
AWS Access Key ID [None]: test
AWS Secret Access Key [None]: test
Default region name [None]: eu-west-1
Default output format [None]:

Confirm if it has been created.


$ cat ~/.aws/config 
[profile localstack]
region = eu-west-1

$ cat ~/.aws/credentials
[localstack]
aws_access_key_id = test
aws_secret_access_key = test

Test


In terminal you should add profile to the command. e.g., $ aws --profile localstack. In your application, use config as shown below.


aws.Config{
Address: "http://localhost:4566",
Region: "eu-west-1",
Profile: "localstack",
ID: "test",
Secret: "test",
}