Building a Production Class Stateful API with AWS API Gateway

Building a Production Class Stateful API with AWS API Gateway
Building a Production Class Stateful API with AWS API Gateway

CLOUD LABS



Building a Production Class Stateful API with AWS API Gateway

In this Cloud Lab, you’ll build and compare stateless vs. stateful HTTP APIs with Lambda and DynamoDB, including edge-case checks and EMF metrics and production-harden services for resilience, scale, and observability.

11 Tasks

beginner

1hr 30m

Certificate of Completion

Desktop OnlyDevice is not compatible.
No Setup Required
Amazon Web Services

Learning Objectives

Hands-on experience implementing a stateless Lambda-based HTTP API using Amazon API Gateway
Working knowledge of using Amazon DynamoDB to persist and retrieve session state
The ability to compare the behavior of stateless and stateful APIs through simulated user interactions
An understanding of observing runtime behavior through logs and metrics using Amazon CloudWatch
The ability to evaluate trade-offs between scalability, resilience, and complexity in stateful vs. stateless designs

Technologies
API Gateway logoAPI Gateway
Lambda logoLambda
DynamoDB logoDynamoDB
CloudWatch logoCloudWatch
Cloud Lab Overview

A stateless API does not maintain any session data or client context between requests; each request is independent and contains all the information the server needs to process. In contrast, a stateful API remembers information about the client across requests, with the server keeping track of user-specific data and using it to modify responses. You can implement stateless and stateful serverless APIs on AWS using API Gateway, Lambda, and DynamoDB.

In this Cloud Lab, you’ll explore the contrast between stateless and stateful API design, while gaining hands-on experience with edge-case handling, logging, and observability best practices. You’ll build two /greet endpoints with API Gateway and Lambda: one stateless (returns a greeting and random fun fact) and one stateful (uses an x-user-id header to read, increment, and store visit counts in DynamoDB). You’ll also make the stateful function more reliable by handling edge cases (like missing headers or DynamoDB errors) and adding JSON logs (EMF) and custom CloudWatch metrics. Finally, you’ll simulate traffic failure to validate that your observability setup gives you clear visibility into reliability and performance.

The following is the high-level architecture diagram of the infrastructure you’ll create in this Cloud Lab:

Architecture diagram for the stateless and stateful APIs backed by Lambda and DynamoDB
Architecture diagram for the stateless and stateful APIs backed by Lambda and DynamoDB
Cloud Lab Tasks
1.Introduction
Getting Started
2.Set Up an HTTP Stateless API
Create a Lambda Function to Handle Stateless API Calls
Deploy a Stateless API with API Gateway
3.Set Up an HTTP Stateful APIs
Create a DynamoDB Table to Track Visit Counts
Create a Lambda Function to Handle Stateful API Calls
Deploy a Stateful API with API Gateway
4.Test and Compare
Validate the API Behavior
5.Enhancing Lambda Resilience and Observability
Database Failure Simulation
Monitor Logs in CloudWatch
6.Conclusion
Clean Up
Wrap Up
Labs Rules Apply
Stay within resource usage requirements.
Do not engage in cryptocurrency mining.
Do not engage in or encourage activity that is illegal.

Before you start...

Try these optional labs before starting this lab.

Relevant Course

Use the following content to review prerequisites or explore specific concepts in detail.

Hear what others have to say
Join 1.4 million developers working at companies like