You don't have to browse the internet too long to realize there are a lot of opt-in forms out there that you can subscribe to. People have typically used email to market and communicate with people. In this tutorial I'll show you how you can leverage AWS resources to make your own opt-in form that will add subscribers to an sns topic. I'll also share some simple Python code that will allow you to mass sms your subscription list. Let's get started.
To do this you'll need to have a basic understanding of the AWS services of EC2, IAM and SNS.
The first thing you'll need to go to IAM and create a role with a AmazonSNSFullAccess policy attached to it. This will give your server access to the SNS service to add subscribers to your mailing list.
You'll also want to navigate to the SNS service and create a new topic where you can collect subscribers phone numbers. Be sure to make a note of the topic arn because you'll need it for your application code on your server.
Set up the Ec2 instance:
We'll launch a basic Amazon Linux instance with a t2.micro. You can use all the default settings but be sure to assign your aforementioned role to the instance and enable an auto-assign public ip.
Set up your instance:
Shell into the box and get it suitably updated by running
sudo yum update
Next we'll install a basic apache server to host our sign up form. Let's do it.
sudo yum install httpd
When it finishes change directories to /var/www and run
rm -rf * to blow away the directories as we will replace them with a git hub checkout. To that end, install git by running
sudo yum install git and then check your write permissions and clone the repo by running
git clone https://github.com/jdav999/snsSignup.git
cd into the snsSignup directory and move the contents up one. At this point your file structure should look like this
Now start the server by running
service start httpd
Point your browser at http://ec2-instance-public-ip/signUp.html and you'll the signup page below.
We need to configure our back end now. We will be using python to add subscriptions into the sns service. Therefore run
pip install boto3
to install boto3 on your box and hence enable the back end application code you got from github. You'll also want to run aws configure to set your default region to us-east-1. You can leave the keys blank because storing access keys on ec2 is just bad news in terms of security and your instance will inherit it's sns communication via the role you assigned it earlier.
Next in /var/www/cgi-bin find calc-script.py and edit line #12 to have your topic arn. If you have done this correctly you can now add subscriptions for your form and see them populate in the subscriptions section of your sns topic.
To fully enable your messaging service edit /var/www/client.py to have you the same topic arn you used earlier. You can now publish to your subscribers by running
python client.py "your message"
There you have it. You now have an active landing page for sms list building.