Building and Troubleshooting a Serverless Web Application

30 minutes
  • 5 Learning Objectives

About this Hands-on Lab

In this hands-on lab, we are going to build and troubleshoot a serverless web application using the following technologies:

* DynamoDB
* Lambda
* API Gateway
* S3
* X-Ray

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create a DynamoDB Table
  1. Create the DynamoDB table and populate it using the file named items.json. All files required for this hands-on lab are located in the folder namedBuilding_and_Troubleshooting_a_Serverless_Web_Application that you will find in the following GitHub repository.
Create a Lambda Function with an API Gateway Endpoint
  1. Create a Lambda function usinglambda_function.py.
  2. Test the function to see if it works.
  3. Diagnose and fix an error with the function configuration.
  4. Add an API gateway endpoint to your function; make sure you select a REST API.
  5. Test that the API gateway can be used to invoke your Lambda function.
Create an S3 Bucket and Upload the Website Files
  1. Modify index.html to add the invoke URL of your API Gateway endpoint.
  2. Create an S3 bucket with public access enabled.
  3. Upload the following website files to your bucket. Make sure they have public-read enabled: index.html, error.html, cookie.html
  4. Configure S3 static website hosting on your S3 bucket.
  5. Check you can access everything from the S3 website-hosting URL.
Configure X-Ray
  1. Enable tracing from within the Lambda function.
  2. Enable the API gateway endpoint to send traces.
  3. Add the Lambda Layer to your function using the file named layer.zip.
  4. Update your Lambda function code to import the X-Ray SDK to your function using the snippet provided named lambda_function_xray.py.
  5. Test the function to see if it works.
  6. Diagnose and fix an error with the function configuration.
Review The X-Ray Service Map
  1. Generate some traffic to your website.
  2. Review the X-Ray service map and traces.
  3. Break the application and see the results displayed in X-Ray.

Additional Resources

Reference Links:

  • All files required for this hands-on lab are located in the folder named Building_and_Troubleshooting_a_Serverless_Web_Application that you will find in the following GitHub repository.
  • Vi Editor cheat sheet
  • Using AWS Lambda with AWS X-Ray

    You will need this script for the Create an S3 Bucket and Upload the Website Files objective:

    {
       "Version": "2012-10-17",
       "Id": "Policy1650555565088",
       "Statement": [
           {
               "Sid": "Stmt1650555563210",
               "Effect": "Allow",
               "Principal": "*",
               "Action": "s3:GetObject",
               "Resource": "arn:aws:s3:::mywebsitefiles6754376825/*"
           }
       ]
    }

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?