Building a Serverless Application Using Step Functions, API Gateway, Lambda, and S3 in AWS

1.75 hours
  • 6 Learning Objectives

About this Hands-on Lab

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:

  1. Create a function, and ensure Author from scratch is selected. Name it email, and use the Python 3.8 runtime.
  2. Change the Default execution role to the existing LambdaRuntimeRole.
  3. In lambda_function.py, delete the existing code, and replace it with the contents of email_reminder.py from the GitHub repo for this lab.
  4. Open Simple Email Service (SES), and create a new identity using your email.
  5. Go to your email, and click the provided verification link in the email.
  6. In lambda_function.py function, change YOUR_SES_VERIFIED_EMAIL to the email address you verified earlier.
  7. Deploy the function, and copy the function ARN for later use.
Create the sms Lambda Function

From the Lambda console:

  1. Create a function, and ensure Author from scratch is selected. Call it sms, and use the Python 3.8 runtime.
  2. Change the Default execution role to the existing LambdaRuntimeRole.
  3. In lambda_function.py, delete the existing code, and replace it with the contents of sms_reminder.py from the GitHub repo for this lab.
  4. Deploy the function, and copy the function ARN for later use.
Create the api_handler Lambda Function

From the Lambda console:

  1. Create a function, and ensure Author from scratch is selected. Call it api_handler, and use the Python 3.8 runtime.
  2. Change the Default execution role to the existing LambdaRuntimeRole.
  3. In lambda_function.py, delete the existing code, and replace it with the contents of api_handler.py from the GitHub repo for this lab.
  4. Deploy the function.
Create a Step Function State Machine

From Step Functions:

  1. Open the Hello World example, and in the line under the Review Hello World example title, click here to access more functionality.
  2. Select Write your workflow in code, and use the Standard type.
  3. Copy and paste the contents of step-function-template.json from the GitHub repo for this lab in the Definition section in Step Functions.
  4. Replace any occurrences of EMAIL_REMINDER_ARN with the ARN of the email Lambda function.
  5. Replace any occurrences of TEXT_REMINDER_ARN with the ARN of the sms Lambda function.
  6. For Permissions, select the RoleForStepFunction existing role, and then create the state machine.
  7. Copy the ARN, and go back to the api_handler function in Lambda.
  8. Replace the SFN_ARN placeholder value in lambda_function.py with the ARN you just copied, and deploy the function and deploy.
Create the API Gateway

From API Gateway:

  1. Select REST API (not the Private one), and select Build.
  2. Use REST for the protocol and create a new API.
  3. Create a New API.
  4. Name the API reminders with the Regional endpoint type.
  5. Create a resource named reminders and Enable API Gateway CORS.
  6. 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
  7. 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.

  8. Copy the Invoke URL for later use.
Create and Test the Static S3 Website
  1. Download a local copy of the static_website folder with its contents from the GitHub repo for this lab.
  2. Open your local formlogic.js file, and replace the API_ENDPOINT placeholder text with the Invoke URL from API Gateway keeping /reminders on the end of the string.
  3. Go to S3, and create a bucket with a globally unique name, ACLs enabled, and remove Block all public access.
  4. Add all files from your local static_website folder. Change the permissions to Grant public-read access, and upload.
  5. Enable Static website hosting, and set the following values:
    • Index document: index.html
    • Error document: error.html
  6. Open the Bucket website endpoint URL to access the webpage.
  7. To test the service’s functionality, set the following values:
    • Seconds to wait: 1
    • Message: Hello
    • someone@something.com: Your email address
  8. Under Reminder Type, select email. You should see {"Status":"Success"} at the bottom of the page.
  9. 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.

  10. Access the Graph inspectior for MyStateMachine in AWS Step Functions to view the event’s visual workflow.

Additional Resources

Log in to the live AWS environment using the credentials provided. Make sure you're in the N. Virginia (us-east-1) region throughout the lab.

All of the resources needed to complete this lab are available from this GitHub repo.

What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Sign In
Welcome Back!

Psst…this one if you’ve been moved to ACG!

Get Started
Who’s going to be learning?