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: