Skip to content

Instantly share code, notes, and snippets.

@thapakazi
Last active March 24, 2023 02:57
Show Gist options
  • Save thapakazi/3b52ab92a80230d688f7535624cad7ac to your computer and use it in GitHub Desktop.
Save thapakazi/3b52ab92a80230d688f7535624cad7ac to your computer and use it in GitHub Desktop.
Using IAM role to send SMS via SNS
1. create sns topic
2. Under Amazon SNS > Text messaging (SMS)
Add your phone number and verify it with otp.
reason:
by default SMS is in sandbox mode: https://docs.aws.amazon.com/sns/latest/dg/sns-sms-sandbox.html
Need to create a support ticket to "Exit SMS Sandbox" :weird: which only allows us to send sms on verified number.
2.1 Create a SMS subscirption with thant number, use SMS protocol
3. Create iam role with policy:
```json
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": "sns:Publish",
"Resource": "arn:aws:sns:us-east-1:xxx:SMS"
}
]
}
```
4. create iam role and attach the policy above
5. Install awscli and test this policy in action
```
aws sts get-caller-identity > /tmp/id; aws sns publish --phone-number +97712345 --message "this is cool $(cat /tmp/id)" --region us-east-1
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment