As part of my own development, I am attempting to run my entire personal project within a single docker compose file and am struggling to add my Local Stack SQS as an event source to my Lambda service.
The flow I'm struggling with is: ReactApp --> Java Service --> AWS SNS --> AWS SQS --> Java Lambda
Everything works well up until the AWS SQS. If I use the AWS CLI to receive the messages from the SQS, I can see they exist. I can then use that as input to a HTTP GET request and can call the Lambda directly. However, I'm struggling to see how to use the AWS CLI / Local Stack / Docker to configure my Lambda service as an event source to the SQS. I think the issue is that Local Stack isn't aware of the Lambda service and it therefore, it doesn't have an ARN reference for me to use in another CLI command within setup-resources
Extract of my docker-compose file is shown below. The proclubsleague-lambda
is built using FROM public.ecr.aws/lambda/java:17
localstack:
image: localstack/localstack:latest
environment:
- SERVICES=sqs,sns,lambda
- DEFAULT_REGION=eu-west-2
- LAMBDA_EXECUTOR=docker
- LAMBDA_REMOTE_DOCKER=true
- LAMBDA_REMOVE_CONTAINERS=true
- DATA_DIR=/tmp/localstack/data
- DEBUG=1
- DOCKER_HOST=unix:///var/run/docker.sock
ports:
- "53:53"
- "443:443"
- "4510-4520:4510-4520"
- "4566-4620:4566-4620"
volumes:
- "${TMPDIR:-/tmp}/localstack:/tmp/localstack"
- /var/run/docker.sock:/var/run/docker.sock
networks:
- localstack
setup-resources:
image: amazon/aws-cli:latest
environment:
- AWS_ACCESS_KEY_ID=key
- AWS_SECRET_ACCESS_KEY=secret
- AWS_DEFAULT_REGION=eu-west-2
entrypoint: /bin/sh -c
command: |
"
sleep 20
aws --endpoint-url=http://host.docker.internal:4566 sns create-topic --name proclubsfa-sns.fifo --region eu-west-2 --output table --attributes FifoTopic=true,ContentBasedDeduplication=false
echo '{\"FifoQueue\": \"true\",\"ContentBasedDeduplication\": \"false\"}' > sqs.json
aws --endpoint-url=http://host.docker.internal:4566 sqs create-queue --queue-name proclubsfa-sqs.fifo --region eu-west-2 --output table --attributes file://sqs.json
aws --endpoint-url=http://host.docker.internal:4566 sns subscribe --topic-arn arn:aws:sns:eu-west-2:000000000000:proclubsfa-sns.fifo --protocol sqs --notification-endpoint arn:aws:sqs:eu-west-2:000000000000:proclubsfa-sqs.fifo --output table
"
depends_on:
- localstack
networks:
- localstack
proclubsleague-lambda:
image: XXX.dkr.ecr.eu-west-2.amazonaws.com/proclubsleague-lambda:latest
ports:
- "9000:8080"
volumes:
- ./:/app
extra_hosts:
- "host.docker.internal:host-gateway"
networks:
- localstack
networks:
localstack:
external: false
driver: bridge
name: localstack
I'm fairly new to all of this. Is there a better way to achieve what I'm trying to do?