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
  1. Open the Simple Email Service console.
  2. Click Email Addresses, verify a new email address, enter your email address to use, and click Verify this address.
  3. Click Close on the dialog box, and click the link in the email you received to verify your email address.
  4. Refresh, and make sure the verification state is verified.
  5. Go to the Lambda console.
  6. Create a function.
  7. Choose Author from scratch, name the function email, and the runtime can be either python 3.6 or python 3.7.
  8. Expand Choose or create an execution role, select Use an existing role, and select the existing role from the dropdown, called LambdaRuntimeRole.
  9. Click Create function, and scroll down to the function code box.
  10. Replace all the code with the code from
  11. Change YOUR_SES_VERIFIED_EMAIL to the email address you verified earlier.
  12. Click Save.
Create the sms Lambda Function

From the Lambda console:

  1. Create a function.
  2. Make sure Author from scratch is selected, call it sms, and select the python 3.6 or python 3.7 runtime.
  3. Expand Choose or create an execution role, pick Use an existing role, and select LambdaRuntimeRole.
  4. Click Create Function.
  5. Scroll down to the function code box.
  6. Delete the existing code, and replace it with the contents of from GitHub.
  7. Click Save.
Create the api_handler Lambda Function

From the Lambda console:

  1. Create function.
  2. Set Author from scratch.
  3. Set the function name to api_handler and the runtime to python 3.6 or python 3.7.
  4. Expand Choose or create an execution role, select Use an existing role, and select LambdaRuntimeRole.
  5. Click Create function.
  6. Scroll down to the function code box, delete the existing code, and replace it with the contents of from GitHub.
  7. At the top of the code, replace STEP_FUNCTION_ARN with the ARN of the state machine you just created.
  8. Ensure you pick the state machine ARN, not the IAM role ARN.
  9. Click Save.
Create a Step Function State Machine
  1. Navigate to the Step Functions console.
  2. Delete any existing state machines.
  3. Note any functions that don’t delete. You need to pick a unique name.
  4. Click Create state machine.
  5. Select Author with code snippets.
  6. For name, enter reminder (ideally) or reminder- with a unique string on the end if reminder is already taken.
  7. Delete the existing snippet, and replace it with the contents of step-function-template.json from GitHub.
  8. You may see red error indicators, and those are fine.
  9. Replace any occurrences of EMAIL_REMINDER_ARN with the ARN of the email Lambda function.
  10. Replace any occurrences of TEXT_REMINDER_ARN with the ARN of the sms Lambda function.
  11. Click Refresh next to the diagram, and ensure it updates to include the flow of steps.
  12. Click Next, select Choose an existing IAM role, select I will use an existing role, and select RoleForStepFunction.
  13. Click Create state machine.
Create the API Gateway

From the API Gateway endpoint:

  1. Click Get Started and OK on any example dialog box.
  2. Select REST and New API.
  3. Set the API name to reminders, and configure it to be a regional API.
  4. Click Create API.
  5. Click Actions and Create Resource.
  6. Call it reminders, and enable Enable API Gateway CORS.
  7. Click Create Resource.
  8. Select /reminders, and click Actions > Create method.
  9. Select POST in the dropdown.
  10. Click the check mark next to POST.
  11. Select POST, ensure Lambda Function is selected and Use Lambda Proxy Integration is checked.
  12. In the Lambda function box, type api_handler and click Save.
  13. Click OK to allow API Gateway permission to invoke the api_handler function.
  14. Select Actions and Deploy API.
  15. Set Deployment stage to New Stage.
  16. Type prod for name and description.
  17. Click Deploy.
  18. You can ignore any errors involving WAF. They don’t impact the lab.
  19. Take note of the Invoke URL. You will need this next.
Create the Static S3 Website

Locate the Local static_website Folder

  1. Open formlogic.js.
  2. Replace the YOUR_API_ENDPOINT_URL placeholder with the invoke URL for the prod API with /reminders appended.

Configure the Static Website

  1. Open the S3 console.
  2. Click Create bucket.
  3. The bucket name will need to be unique, and ensure the region is US East (N. Virginia).
  4. Click Next.
  5. Click Next again.
  6. Ensure no checkmarks are selected on the block public access screen. This includes individual ones and any group check mark.
  7. Click Next and then Create bucket.
  8. Open the bucket.
  9. Click Upload, select the objects from the static_website folder, and click Next.
  10. Change the Manage public permissions dropdown to Grant public read access to this object(s).
  11. Click Next, Next again, and Upload.
    • If you get any errors here, verify the files are public by clicking one, selecting Permissions, and ensuring public access is set so everyone has read object permissions.
  12. Head back to your bucket, and click the Properties tab.
  13. Click Static website hosting.
  14. Select Use this bucket to host a website.
  15. Enter index.html in the Index Document box, and error.html in the Error Document box.
  16. Click Save.
  17. Browse to the Static Website Hosting Endpoint URL for the bucket (the link is on the static website hosting option screen).
  18. Test it out.

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.

If you'd like to follow one of the optional steps below involving the Postman app, you can download the app here.

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?