AWS Lambda to Amazon SNS

AWS Lambda → SNS → Mobile device

Create a Lambda function that publishes directly to a phone number using SNS

The CDK template deploys a Lambda function with IAM permissions configured to publish an SMS message to a US phone number using a 10-digit long code (10DLC). The Lambda function publishes a message to the phone number when invoked. The AWS CDK template deploys the resources and the IAM permissions required to run the application.

< Back to all patterns

GitHub icon Download this pattern (.zip)

GitHub icon View this pattern on GitHub


Clone repo

git clone https://github.com/aws-samples/serverless-patterns/cd serverless-patterns/lambda-sns-sms-cdk

Deploy

sam deploy --guided


Testing

Use the AWS CLI to invoke the Lambda function. The function name is in the outputs of the AWS SAM deployment (the key is TopicPublisherFunction):
1. Invoke the Lambda function to publish a message to SNS: aws lambda invoke --function-name ENTER_YOUR_FUNCTION_NAME response.json.

Cleanup

1. Delete the stack: npx cdk destroy.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus".
3. You see a message confirming DELETE_COMPLETE.

Created by:

Ian Larson

Ian Larson

Ian is a Sr. Cloud Infrastructure Architect with AWS. When he's not building cloud solutions with AWS customers, he can be found on his bike exploring the roads less traveled.