AWS Lambda to Amazon SNS

AWS Lambda → SNS → Mobile device

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

The SAM template deploys a Lambda function, and the IAM permissions required to publish an SMS message directly to a phone number via SNS.
The Lambda function handler uses the AWS SDK for javascript to send an SMS message using a 10-digit long code (10DLC) as the SMS origination number.

< 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

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 outfile.txt.

Cleanup

1. Delete the stack: sam delete --stack-name STACK_NAME.
2. Confirm the stack has been deleted: aws cloudformation list-stacks --query "StackSummaries[?contains(StackName,'STACK_NAME')].StackStatus"

Created by:

Benjamin Smith

Benjamin Smith

Ben is a senior developer advocate for Serverless Applications at Amazon Web Services based in London, UK. Prior to joining AWS Ben worked in a number of different technical roles specializing in workflow Automation and web development.

Follow on LinkedIn