In this AWS hands-on lab, we will create a fully working serverless reminder application using S3, Lambda, API Gateway, Step Functions, Simple Email Service, and Simple Notification Service.
While the lab does use Python and JavaScript, you don’t need to be able to code to understand and implement the solution. By the end of the lab, you will feel more comfortable architecting and implementing serverless solutions within AWS.
Let’s get started!
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Create the email Lambda Function
All of the resources needed to complete this lab are available from this GitHub repo:
https://github.com/ACloudGuru-Resources/lab-building-a-serverless-application-using-step-functions-api-gateway-lambda-and-s3-in-aws
From the Lambda console:
- Create a function, and ensure Author from scratch is selected. Name it email, and use the Python 3.8 runtime.
- Change the Default execution role to the existing LambdaRuntimeRole.
- In
lambda_function.py
, delete the existing code, and replace it with the contents ofemail_reminder.py
from the GitHub repo for this lab. - Open Simple Email Service (SES), and create a new identity using your email.
- Go to your email, and click the provided verification link in the email.
- In
lambda_function.py
function, changeYOUR_SES_VERIFIED_EMAIL
to the email address you verified earlier. - Deploy the function, and copy the function ARN for later use.
- Create the sms Lambda Function
From the Lambda console:
- Create a function, and ensure Author from scratch is selected. Call it sms, and use the Python 3.8 runtime.
- Change the Default execution role to the existing LambdaRuntimeRole.
- In
lambda_function.py
, delete the existing code, and replace it with the contents ofsms_reminder.py
from the GitHub repo for this lab. - Deploy the function, and copy the function ARN for later use.
- Create the api_handler Lambda Function
From the Lambda console:
- Create a function, and ensure Author from scratch is selected. Call it api_handler, and use the Python 3.8 runtime.
- Change the Default execution role to the existing LambdaRuntimeRole.
- In
lambda_function.py
, delete the existing code, and replace it with the contents ofapi_handler.py
from the GitHub repo for this lab. - Deploy the function.
- Create a Step Function State Machine
From Step Functions:
- Open the Hello World example, and in the line under the Review Hello World example title, click here to access more functionality.
- Select Write your workflow in code, and use the Standard type.
- Copy and paste the contents of
step-function-template.json
from the GitHub repo for this lab in the Definition section in Step Functions. - Replace any occurrences of
EMAIL_REMINDER_ARN
with the ARN of theemail
Lambda function. - Replace any occurrences of
TEXT_REMINDER_ARN
with the ARN of thesms
Lambda function. - For Permissions, select the RoleForStepFunction existing role, and then create the state machine.
- Copy the ARN, and go back to the
api_handler
function in Lambda. - Replace the
SFN_ARN
placeholder value inlambda_function.py
with the ARN you just copied, and deploy the function and deploy.
- Create the API Gateway
From API Gateway:
- Select REST API (not the Private one), and select Build.
- Use REST for the protocol and create a new API.
- Create a New API.
- Name the API reminders with the Regional endpoint type.
- Create a resource named reminders and Enable API Gateway CORS.
- Create a POST method for /reminders, and set the following values:
- Integration type: Lambda Function
- Use Lambda Proxy integration: Selected
- Lambda Region: us-east-1
- Lambda Function: api_handler
- Deploy the API by setting the following values:
- Deployment stage: New Stage
- Stage name: prod
Note: You may ignore any Web Application Firewall (WAF) permissions warning messages received after deployment.
- Copy the Invoke URL for later use.
- Create and Test the Static S3 Website
- Download a local copy of the
static_website
folder with its contents from the GitHub repo for this lab. - Open your local
formlogic.js
file, and replace theAPI_ENDPOINT
placeholder text with the Invoke URL from API Gateway keeping/reminders
on the end of the string. - Go to S3, and create a bucket with a globally unique name, ACLs enabled, and remove Block all public access.
- Add all files from your local
static_website
folder. Change the permissions to Grant public-read access, and upload. - Enable Static website hosting, and set the following values:
- Index document: index.html
- Error document: error.html
- Open the Bucket website endpoint URL to access the webpage.
- To test the service’s functionality, set the following values:
- Seconds to wait: 1
- Message: Hello
- someone@something.com: Your email address
- Under Reminder Type, select email. You should see
{"Status":"Success"}
at the bottom of the page. - Check your email. You should now see a reminder email from the service.
Note: Check your spam folder if you do not see it in your inbox.
- Access the Graph inspectior for
MyStateMachine
in AWS Step Functions to view the event’s visual workflow.
- Download a local copy of the