Is there any way to automatically create SQS Queus using localstack with docker-compose.yml?
My docker-compose.yml:
version: '3.8'
services:
localstack:
image: localstack/localstack
ports:
- "4566:4566"
- "4571:4571"
- "${PORT_WEB_UI-8080}:${PORT_WEB_UI-8080}"
environment:
- SERVICES=${SERVICES- }
- DEBUG=${DEBUG- }
- DATA_DIR=${DATA_DIR- }
- PORT_WEB_UI=${PORT_WEB_UI- }
- LAMBDA_EXECUTOR=${LAMBDA_EXECUTOR- }
- KINESIS_ERROR_PROBABILITY=${KINESIS_ERROR_PROBABILITY- }
- DOCKER_HOST=unix:///var/run/docker.sock
volumes:
- "${TMPDIR:-/tmp/localstack}:/tmp/localstack"
I would like to have some queues created when start docker-compose instead of create it manually.
If you want to automatically bootstrap all needed queues on docker up, you can add a shell script that will be run by localstack on docker container start.
Here is an example.
Add to your volumes the following:
- ./localstack_bootstrap:/docker-entrypoint-initaws.d/
Then add to the directory specified above (localstack_bootstrap in my case) a shell script with any name you like (I decided to call it sqs_bootstrap.sh) with the following contents:
#!/usr/bin/env bash
set -euo pipefail
# enable debug
# set -x
echo "configuring sqs"
echo "==================="
LOCALSTACK_HOST=localhost
AWS_REGION=eu-central-1
create_queue() {
local QUEUE_NAME_TO_CREATE=$1
awslocal --endpoint-url=http://${LOCALSTACK_HOST}:4566 sqs create-queue --queue-name ${QUEUE_NAME_TO_CREATE} --region ${AWS_REGION} --attributes VisibilityTimeout=30
}
create_queue "queue1"
create_queue "queue2"
Don't forget to run chmod +x ./localstack_bootstrap/sqs_bootstrap.sh.
More details on that I've found here - https://joerg-pfruender.github.io/software/docker/microservices/testing/2020/01/25/Localstack_in_Docker.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With