Cloud Project #1, Serverless Sending Application

This article is a beginner’s guide to my exploring opportunities around building mini-cloud projects. This first project entails building a serverless SMS/Email sending application for sending Email and SMS from a website(hosted on Amazon S3) using AWS serverless services(SES and SNS).

The Project:

0. This project employs AWS Lambda — a serverless, event/response driven compute service that lets you run code for any type of application or service without provisioning or managing servers. Lambda’s strength lies in its ability to interact with other AWS services. In this project, Lambda interacts with Amazon Simple Notification Service(SNS) for sending SMS, Amazon Simple Email Service(SES) for sending email, and StepFunctions to send data received from an API. For Lambda to talk to these services, it needs permission to use them.

  1. I created a Lambda Role via Identity Access Management(IAM) which contains full access permissions for Lambda functions(deployed in a later phase) to interact with SNS for sending SMS, SES for sending email, and StepFunctions to send data received from an API.

  2. Two Lambda python functions were created via AWS Lambda; both of which use the Lambda Role created earlier. The first Lambada function(email.py) configures an SES identity(a source email address) with an instruction to send an email message to a recipient email address input from a website page. The second Lambda function(sms.py) configures an SNS identity(a source phone number) to send an SMS message to a recipient phone number input from a website page. Both Lambda functions send a return message to a StepFunctions state machine to confirm they are been activated.

  3. StepFunctions was used to create a state machine; a state machine confirms the type of sending — either SMS or Email(whichever input from the website page) to a recipient's email address or phone number. The state machine(written in JSON) embodies two states: an Email State which holds the ARN of the email.py Lambda function; and an SMS State which holds the ARN of the sms.py Lambda function.

4. I created a third Lambda python function(restapiHandler.py) which uses the existing Lambda Role; this function captures the StepFunctions state machine ARN created earlier, it receives data sent by a REST API, and returns the data to the StepFunctions state machine.

5. Amazon API Gateway was used to create a REST API; an API act as a front door for applications to access data, business logic, or functionality from its backend services. The REST API(which uses a POST method) captures the restapiHandler.py Lambda function created earlier; such that for every POST method(data published from the website page to the API), the REST API will receive the data and pass it to the restapiHanlder.py function. The REST API is deployed to a website's Javascript code via an API URL. I verified the REST API Invoked URL with the Postman API platform.

6. I created a website page(index.html) which is a form to fill in a message and the recipient's phone number/email address; the HTML website page is linked to a script(formToApi.js) capable of sending the data filled on the website page to the REST API URL. I uploaded the html and script files to an S3 bucket which uses a static website hosting configuration and a bucket policy to make the website page publicly accessible online.