- Lab
- A Cloud Guru
Deploying a Serverless Application Using AWS Lambda, API Gateway, and DynamoDB
During this hands-on lab you will explore how to create and host an entirely serverless application leveraging some of the most popular AWS offerings. You will deploy the application using an architecture that uses Amazon API Gateway, AWS Lambda, and Amazon DynamoDB. Let's get building!
Path Info
Table of Contents
-
Challenge
Create the DynamoDB Table
Create a DynamoDB table with the following settings:
- Table Name:
Quotes
- Partition Key Name:
quote
with typeString
- Sort Key Name:
author
with typeString
- Table settings:
Customize settings
- Table class:
DynamoDB Standard
- Read/write Capacity mode:
Provisioned
- Read Capacity Auto scaling:
On
- Minimum capacity units:
1
, Maximum capacity units:5
, Target utilization (%) :20
- Write capacity Auto scaling:
On
- Minimum capacity units:
1
, Maximum capacity units:5
, Target utilization (%) :20
- Encryption at rest:
AWS managed key
- Table Name:
-
Challenge
Create Lambda Functions
Create two different Lambda functions to leverage with Amazon API Gateway.
The code for each function is provided to you, so you do not need to type these manually.
PutQuotes Function
- Function Name:
PutQuotes
- Timeout:
1 Minute
- Environment Variable Key:
TABLE_NAME
- Environment Variable Value:
Quotes
- New Execution Role Name:
PutQuotesRole
- Permissions Template: Simple microservice permissions (AWS sample)
- Python Code
GetQuotes Function
- Function Name:
GetQuotes
- Timeout:
1 Minute
- Environment Variable Key:
TABLE_NAME
- Environment Variable Value:
Quotes
- New Execution Role Name:
GetQuotesRole
- Permissions Template: Simple microservice permissions (AWS sample)
- Python Code
- Function Name:
-
Challenge
Create Regional REST API
In Amazon API Gateway create a new API resource with the following information:
- API Name:
Quotes
- API Type: Regional
Now, create two new resources for use within the application. These resources should be created at the root (Example: /PutQuotes)
Resource: PutQuotes
- Resource Name:
PutQuotes
- Method Type: ANY
- Integration Type: Lambda Function
- Lambda Proxy Integration: Disabled
- Lambda Function: PutQuotes
Resource: GetQuotes
- Resource Name:
GetQuotes
- Method Type: ANY
- Integration Type: Lambda Function
- Lambda Proxy Integration: Enabled
- Lambda Function: GetQuotes
- API Name:
-
Challenge
Create Lambda Function Roles
This should be created while you create the Lambda functions.
- PutQuoutes Role Name:
PutQuotesRole
- GetQuotes Role Name:
GetQuotesRole
Each Role needs the ability to write to Amazon CloudWatch Logs, and it needs to be able to read and write to your Amazon DynamoDB
Quotes
table. - PutQuoutes Role Name:
-
Challenge
Deploy, Log, and Test
- Deploy the
Quotes
REST API to a new stage. - Under API Gateway Settings, set up a
CloudWatch log role
using the ARN from the IAM role that was created for you calledOurApiGatewayToCloudWatchLogsRole
- Under Logs and tracing settings of the
Quotes
REST API, set CloudWatch logs to Full requests and response logs and Enable X-Ray tracing. - Navigate to the invoke URL provided and append
/PutQuotes
to the end and hit Enter. - You will receive a message saying Item successfully written to DynamoDB if working correctly.
- Refresh the page several times and verify that the function is working as intended by exploring the DynamoDB table items.
- Replace the
/PutQuotes
resource with/GetQuotes
in the Invoke URL. - You should receive a simple message with a quote! Refresh to randomly select quotes from the database.
- Deploy the
What's a lab?
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.
Provided environment for hands-on practice
We will provide the credentials and environment necessary for you to practice right within your browser.
Guided walkthrough
Follow along with the author’s guided walkthrough and build something new in your provided environment!
Did you know?
On average, you retain 75% more of your learning if you get time for practice.