In this example, we demonstrate SNS delivery to SQS queues via subscriptions, Lambda invocations through SQS event source mappings, and accessing LocalStack services from Lambda function.
The basic pipeline is:
- Publish -> SNS Topic (via user input)
- SNS Topic -> SQS queue (via SNS subscription)
- SQS Queue -> Lambda invocation (Lambda event source mapping)
- Lambda -> SQS (via AWS SDK
boto3from within a Lambda) - SQS -> Receive message (via user input)
- A valid LocalStack for AWS license. Your license provides a
LOCALSTACK_AUTH_TOKEN. - Docker
localstackCLIawslocalCLI- Pulumi
pulumilocalCLImakeandjq
export LOCALSTACK_AUTH_TOKEN=<your-auth-token>
localstack auth set-token $LOCALSTACK_AUTH_TOKEN
localstack start -d
localstack wait -t 30pulumilocal stack init dev
pulumilocal config set aws:region us-east-1Install the dependencies via:
yarn installZip the Lambda function via:
zip lambda.zip lambda.pyTo preview and deploy the stack, run:
pulumilocal upAfter the Pulumi stack has been deployed, you should be able to check the available SQS queues & SNS topics via:
awslocal sqs list-queues
awslocal sns list-topicsYou can publish a message to the SNS topic via:
awslocal sns publish \
--topic arn:aws:sns:us-east-1:000000000000:trigger-event-topic \
--message '{"event_type":"testing","event_payload":"hello world"}'You can receive the message from the SQS queue via:
awslocal sqs receive-message --wait-time-seconds 10 --visibility-timeout=0 \
--queue=http://localhost:4566/000000000000/lambda-result-queue \This code is available under the Apache 2.0 license.