Use CloudFormation to specify SMS (short message) as the destination for SNS notifications
As indicated on the following pages, there are a number of destinations available for notifications of SNS events.
This page confirms how to notify SMS (Short Message Service).
Environment
Create two resources.
The first is SNS topics.
Select SMS as the notification destination and specify a cell phone number.
The second is a Lambda function.
This function acts as a publisher that sends messages to SNS topics.
The runtime environment for the function is Python 3.12.
CloudFormation template files
The above configuration is built with CloudFormation.
The CloudFormation template is placed at the following URL
Explanation of key points of template files
SNS Topics
Resources:
Topic:
Type: AWS::SNS::Topic
Properties:
FifoTopic: false
Subscription:
- Endpoint: !Ref PhoneNumber
Protocol: sms
TopicName: !Sub "${Prefix}-sns-topic"
Code language: YAML (yaml)
The Subscription property is the key point.
Specify the cell phone number to be notified in the Endpoint property.
Specify “sms” for Protocol property.
(Reference) Lambda function
The role of this function is to send a message to the SNS.
The following settings are used to notify messages.
- Title: hogehoge
- Body: fugafuga
For the specific code to be executed by the function, please refer to the following page.
Architecting
Use CloudFormation to build this environment and check its actual behavior.
Create a CloudFormation stacks and check the resources in the stacks
Create CloudFormation stacks.
For information on how to create stacks and check each stack, please refer to the following pages.
Check the SNS.
The SNS topic has been successfully created.
When I check the device subscribing to this topic, it does indeed specify “SMS” as the protocol and a phone number as the endpoint.
Check the Lambda function.
The Lambda function is successfully created.
(Reference) If your AWS account is in the SMS sandbox, register the phone number to be notified in advance.
Before checking the operation, care must be taken.
By default, your AWS account is in the SMS Sandbox.
The AWS official description of the SMS sandbox is as follows
When you start using Amazon SNS to send SMS messages, your AWS account is in the SMS sandbox. The SMS sandbox provides a safe environment for you to try Amazon SNS features without risking your reputation as an SMS sender.
SMS sandbox
Also, if your AWS account is in the SMS sandbox, it is important to
You can send SMS messages only to verified destination phone numbers.
SMS sandbox
Before operating, register the phone number to be notified.
Click on “Add phone number”.
After entering the phone number to be registered, press “Add phone number”.
A one-time password for authentication was sent to the SMS application on the designated cell phone.
Enter this on the registration page.
After entering the one-time password, press “Verify phone number”.
A phone number has been registered.
You can now notify this number of your message.
Operation Check
Now that we are ready, we execute the Lambda function.
function has been successfully executed.
The message has now been sent to the SNS topic.
Check the SMS application on your phone again.
Sure enough, a message (fugafuga) was sent.
The string (hogehoge) specified as the subject seems to be ignored.
Summary
We have introduced how to designate SMS as the notification destination for SNS.