How to send SMSin python using AWS SNS

We live in the World of messengers and this might be not relevant tutorial, however this is not true. Sometimes we may need short text message to notify someone about something (for example, someone with not fancy phone or someone who does not have Internet available on their phone or we just need to send short message about accident on the server or just to send message to our grandparents). With that in mind, let's take a look at Amazon SNS service with SMS option.

I have been working with Twilio the other day, which appears to be the easiest to use, affordable pricing and very rich API. But in the scope of this tutorial I really want to focus on AWS services.


This is what we will need in order to successfully walk through this document:

  • AWS account (you may want to check AWS free tier) and sign up super quickly if you have not yet;
    • IAM User with specific policy attached (if you want to make sure your user is able to do only what you need in the scope of this tutorial);
    • SMS properties configured properly (in the region where it is supported);
  • AWS SDK of your choice (here we are going to use Amazon SDK for Python) and computer with operating system of your choice (I am on mac Sierra);
  • Mobile phone to send it out.

I am not going to walk through all prerequisites since some of them are very straight forward.

IAM user and policy

Let's first log in to our AWS console and create our IAM user in order to make API calls towards our account. Let's create IAM user and set Access type to "Programmatic access". Grab access and secret key and now let's assign new policy with our new user.

  "Version": "2012-10-17",
  "Statement": [{
      "Effect": "Deny",
      "Action": [
      "Resource": "arn:aws:sns:*:*:*"
      "Effect": "Allow",
      "Action": [
      "Resource": "*"

This policy is exactly what we need: it does not allow to publish to topics and applications (push notifications), but it does allow to publish SMS. Great!

If you want to deal with IAM policies like a boss, I encourage you to check CloudBerry Explorer since it has wizard to design your policies.

AWS SNS configuration

Now, let's go ahead and configure our SMS preferences in AWS account. At the time of this tutorial AWS offers only few regions with SMS support (three if I am not mistaken). So my region is eu-west-1 (Ireland).

AWS SES SMS configuration

You may want to change "Default message type" if you have critical text message and you want to process them accordingly. Set "Account spend limit" and other options as well if you feel you need it. And this point your configuration is done. Make sure you remember the region, since you need to use this in your SDK later on.

AWS SDK for Python

I assume that you have Python and package manager on your computer. So we don't spend time on this. If you have not I suggest to check Python Beginner's guide, where you'll learn what you need for the below.

The only thing we need here is boto3 which allows us to work with AWS from our Python code. Let's quickly install it from package manager:

pip3 install boto3

I am using Python 3.6.

Sending SMS

Now we can send our SMS with the following few lines:

import boto3

# Create an SNS client
client = boto3.client(

# Send your sms message.
    Message="This is Amazon SNS service talking!"

Make sure YOUR_PHONE_GOES_HERE is set in E.164 format.

SMS pricing

I did not make research and comparison with other available services. Before starting mass SMS, check out SMS pricing section of AWS. It supports 200+ countries and you can check it out for your location. For example United States sounds affordable to me:

Amazon SNS (SMS text messages) pricing

That's it! You should receive SMS from "NOTICE" sender, which is default sender ID. You may want to change it in "Default sender ID" in SMS preferences in your SNS configuration. Hope it helps someone!

In short, this is about:
#amazon sns

Start discussion:
Related articles:
In this article we are going to set up CloudFront for static site. And there is nice tip how to nested content (i.e. subfolders) available. ... more
In this very short tutorial we are going to mount S3 bucket from AWS to the local folder of Debian. ... more
Learn how to mount S3 bucket to your Mac OS ... more
over 5 years#amazon s3 #mac #amazon
August, 9th, 2016 - passed my Amazon CSAA. Few tips I'd love to share here. ... more
Amazon Web Services (AWS) has its own AWS Linux AMI (also free tier). There are several reasons you want to use this AMI for your projects. ... more
AWSRus — Official AWS User Group Russia (St. Petersburg). ... more
about 5 years#meetup #awsrus #amazon
CloudAcademy webinar: how to use AWS services for Backup and DR challenges. I am presenter! ... more
AWS Elastic File System is scalable file system in the cloud, requires NFSv4.1 client and does not support Windows at the moment. However let's see what we can do.. ... more
It's been written many times, however there is no consistency how to make static web site with SSL and SEO friendly urls (301 redirect). Pure AWS based services static website ahead, check details inside! ... more
AWS SES supports SMTP settings for sending through it-self. This is really helpful if we want to configure personal outbound server. ... more
over 4 years#aws ses #smtp #amazon
Launching AWS EC2 can be supplied by something what is known as "user data" and it helps to have things ready before you access it. ... more
How to pre-deploy App using user data script for Windows OS with powershell powered script in EC2? Example inside. ... more
I made light talk on one of our recent #AWSRus community gathering in Moscow and decided to discover this topic with further series of posts in my blog covering various AWS services. ... more
over 4 years#free tier #amazon