AWS Localstack

A fully functional local cloud stack

Profile settings for CLI/SDK access to localstack

config

1
2
[profile localstack]
region = ap-southeast-2

credentials

1
2
3
[localstack]
aws_access_key_id = test
aws_secret_access_key = test

Dynamodb

  1. From compose bring up image: localstack/localstack. Note that environment:SERVICES can be comma delimited. Example SERVICES=dynamodb,secretsmanager
1
2
3
4
5
6
7
8
9
10
localstack:
container_name: localstack
image: localstack/localstack
ports:
- "5007:4566"
environment:
- SERVICES=dynamodb
- DEBUG=1
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
  1. Use an ephemeral container to provision resources using image: amazon/aws-cli
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
localstack_resources:
container_name: localstack_resources
image: amazon/aws-cli
environment:
- AWS_ACCESS_KEY_ID=test
- AWS_SECRET_ACCESS_KEY=test
- AWS_DEFAULT_REGION=ap-southeast-2
entrypoint: /bin/sh -c
command: >
"
# Give localstack a chance to sort out its life
sleep 15;

echo Provision dynamo db tables Porky-Audits
aws dynamodb create-table \
--table-name Porky-Audits \
--attribute-definitions AttributeName=AuditId,AttributeType=S \
--key-schema AttributeName=AuditId,KeyType=HASH \
--provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 \
--endpoint-url=http://localstack:4566;
"
depends_on:
- localstack

S3

1
2
environment:
- SERVICES=s3
1
2
3
4
5
6
command: >
"
echo Provision simple storage
aws s3 mb s3://localstack-porky-bucket \
--endpoint-url=http://localstack:4566;
"

Secrets Manager

1
2
environment:
- SERVICES=secretsmanager
1
2
3
4
5
6
7
8
command: >
"
echo Provision Secrets manager
aws secretsmanager create-secret \
--endpoint-url=http://localstack:4566 \
--name PorkyEncryptionMasterKey \
--secret-string bXlzZWNyZXQ=
"

SQS

1
2
environment:
- SERVICES=sqs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
command: >
"
echo Creating dead letter queue
aws sqs create-queue \
--queue-name foo_queue_dlq \
--endpoint-url=http://localstack:4566;

echo Creating simple queue
aws sqs create-queue \
--queue-name foo_queue \
--attributes ReceiveMessageWaitTimeSeconds=30 \
--endpoint-url=http://localstack:4566;

aws sqs set-queue-attributes \
--queue-url http://localstack:4566/000000000000/foo_queue \
--attributes '{\"RedrivePolicy\": \"{\\\"deadLetterTargetArn\\\":\\\"arn:aws:sqs:ap-southeast-2:000000000000:foo_queue_dlq\\\",\\\"maxReceiveCount\\\":\\\"5\\\"}\"}' \
--endpoint-url=http://localstack:4566;
"