Running Localstack with Docker

Marcos
3 min readOct 16, 2022

--

Localstack is a powerful cloud tool that helps in studies and tests

This is the first post of a serie about localstack and its use for daily studies

What is LocalStack?

From its READ.me:

LocalStack 💻 is a cloud service emulator that runs in a single container on your laptop or in your CI environment. With LocalStack, you can run your AWS applications or Lambdas entirely on your local machine without connecting to a remote cloud provider! Whether you are testing complex CDK applications or Terraform configurations, or just beginning to learn about AWS services, LocalStack helps speed up and simplify your testing and development workflow.

The official documentation is here: https://docs.localstack.cloud/overview/

Running Localstack

For this example we will use a docker-compose.yml file:

version: "3.8"

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" # ext services port range
- "127.0.0.1:53:53" # DNS config
- "127.0.0.1:53:53/udp" # DNS config
- "127.0.0.1:443:443" # LocalStack HTTPS Gateway
environment:
- DEBUG=${DEBUG-}
- PERSISTENCE=${PERSISTENCE-}
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR-}
- LOCALSTACK_API_KEY=${LOCALSTACK_API_KEY-} # only required for Pro
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack"
- "/var/run/docker.sock:/var/run/docker.sock"

This example was given by the official documentation (link in the references).

After creating your .yml file, execute docker-compose up on a terminal:

docker-compose up

Verifying what services are available

Access http://localhost:4566/health and the answer is something like that:

{
"features": {
"initScripts": "initialized"
},
"services": {
"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",
"secretsmanager": "available",
"ses": "available",
"sns": "available",
"sqs": "running",
"ssm": "available",
"stepfunctions": "available",
"sts": "available",
"support": "available",
"swf": "available",
"transcribe": "available"
},
"version": "1.1.1.dev"
}

Note that the port is the gateway port of localstack port, it’s the way to enter and access services.

Creating a queue using SQS

At first use the command docker ps to identify the localstack container:

docker ps

And the result:

Then, access the bash of this container using the command below passing the container id:

docker exec -it id_container /bin/bash

Now, inside the container you may create a service using this command:

awslocal sqs create-queue --queue-name test-queue

Now, it’s time to verify if the queue was created using this command:

awslocal sqs list-queues

And the result is something like this:

That’s it for today. In the next, we will build a spring boot application that will consume this queue.

References:

--

--