Skip to content

Commit 260e2e5

Browse files
committed
revamp the README (#34)
1 parent 40ca1bf commit 260e2e5

File tree

1 file changed

+125
-67
lines changed

1 file changed

+125
-67
lines changed

README.md

Lines changed: 125 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -1,97 +1,132 @@
1-
# Serverless Quiz App
2-
3-
This project showcases a fully serverless quiz application designed to demonstrate LocalStack's capabilities in supporting local cloud development, debugging, and testing throughout the entire software development lifecycle (SDLC).
4-
The application enables users to create quizzes, participate by submitting answers, and view leaderboards for top scores.
5-
It leverages various LocalStack features to highlight the platform's capabilities, including:
6-
7-
- Emulating cloud environments locally with **Core Cloud Emulator**.
8-
- Utilizing **Resource Browsers** for inspecting local resources.
9-
- Gaining insights into your development environment with **Stack Insights**.
10-
- Integrating continuous testing with **LocalStack GitHub Actions** and **SDK**.
11-
- Streaming security policies to refine access controls with **IAM Policy Stream**.
12-
- Managing state snapshots and injecting resource state with **Cloud Pods**.
13-
- Implementing chaos engineering to test system resilience with **Chaos API**.
14-
- Utilizing **Ephemeral Instances** for temporary, isolated testing environments.
15-
- Extending functionality with **LocalStack Extensions** for enhanced development workflows.
1+
# Developing & testing Serverless Quiz App with LocalStack's Platform features
2+
3+
| Key | Value |
4+
| ------------ | ------------------------------------------------------------------------------------ |
5+
| Environment | LocalStack, AWS |
6+
| Services | DynamoDB, SQS, Lambda, API Gateway, SNS, EventBridge, Step Functions, CloudFront, S3 |
7+
| Integrations | AWS CDK, AWS SDK, pytest, GitHub Actions |
8+
| Categories | Serverless, Event-Driven Architecture |
9+
| Level | Advanced |
10+
| Use Case | Cloud Emulation, Resource Browsers, Chaos Engineering, Cloud Pods, Integration Testing, IAM Policy Stream, Ephemeral Instances, Extensions |
11+
| GitHub | [Repository link](https://github.com/localstack-samples/sample-serverless-quiz-app) |
12+
13+
## Introduction
14+
15+
This sample demonstrates how to build a fully serverless quiz application that showcases LocalStack's comprehensive platform capabilities for local cloud development, debugging, and testing throughout the entire software development lifecycle (SDLC). Starting from a simple idea of creating interactive quizzes, the application evolves into a sophisticated demonstration of event-driven serverless architecture, complete with user submissions, scoring mechanisms, and leaderboards. To test this application sample, we will demonstrate how you use LocalStack to deploy complex serverless infrastructure on your developer machine, leverage advanced LocalStack features like Cloud Pods and Chaos Engineering, and validate the complete workflow locally with comprehensive testing and monitoring capabilities.
16+
17+
**NOTE**: This application showcases LocalStack's advanced platform features and serves as a comprehensive reference for teams looking to adopt LocalStack for their entire development lifecycle, from local development through production deployment.
1618

1719
## Architecture
1820

19-
![Application Architecture](images/architecture.png)
21+
The following diagram shows the architecture that this sample application builds and deploys:
2022

21-
The following resources are being deployed:
23+
![Application Architecture](images/architecture.png)
2224

23-
- **DynamoDB**: Stores quiz metadata in `Quizzes` and user data in `UserSubmissions` with indexing for leaderboards.
24-
- **SQS**: Manages async submissions via `QuizSubmissionQueue`, with a DLQ for failed messages.
25-
- **Lambda**: Executes serverless functions for creating, submitting, scoring, and fetching quizzes.
26-
- **IAM**: Defines roles and policies to grant Lambdas and state machines access to necessary resources.
27-
- **API Gateway**: Exposes REST endpoints for quiz operations, linking HTTP methods to Lambda functions.
28-
- **SNS**: Sends alerts via `DLQAlarmTopic` and triggers `QuizzesWriteFailures` for chaos testing.
29-
- **EventBridge Pipes**: Connects `QuizSubmissionDLQ` to SNS to handle dead-letter queue notifications.
30-
- **Step Functions**: Manages email notification workflows with `SendEmailStateMachine`.
31-
- **CloudFront**: Delivers frontend assets from S3 globally for fast user access.
32-
- **S3**: Hosts static frontend assets in `webapp` bucket for CloudFront distribution.
25+
- [DynamoDB Tables](https://docs.localstack.cloud/aws/services/dynamodb/) for storing quiz metadata (`Quizzes`) and user submissions (`UserSubmissions`) with indexing for leaderboards
26+
- [SQS](https://docs.localstack.cloud/aws/services/sqs/) for managing asynchronous submissions via `QuizSubmissionQueue` with Dead Letter Queue for failed processing
27+
- [Lambda Functions](https://docs.localstack.cloud/aws/services/lambda/) for serverless execution of quiz operations: create, submit, score, and retrieve quiz data
28+
- [API Gateway](https://docs.localstack.cloud/aws/services/api-gateway/) exposing REST endpoints for quiz operations with Lambda integrations
29+
- [SNS Topics](https://docs.localstack.cloud/aws/services/sns/) for alert notifications via `DLQAlarmTopic` and chaos testing triggers
30+
- [EventBridge Pipes](https://docs.localstack.cloud/aws/services/eventbridge/) connecting Dead Letter Queue to SNS for failure notifications
31+
- [Step Functions](https://docs.localstack.cloud/aws/services/stepfunctions/) managing email notification workflows with `SendEmailStateMachine`
32+
- [CloudFront Distribution](https://docs.localstack.cloud/aws/services/cloudfront/) for global delivery of frontend assets with caching
33+
- [S3 Bucket](https://docs.localstack.cloud/aws/services/s3/) hosting static frontend assets for CloudFront distribution
34+
- [IAM Roles and Policies](https://docs.localstack.cloud/aws/services/iam/) defining least-privilege access for all services
3335

3436
## Prerequisites
3537

36-
Some of the features in this sample app require a LocalStack Pro license - make sure your Auth Token is configured in your terminal session.
38+
- [`localstack` CLI](https://docs.localstack.cloud/getting-started/installation/#localstack-cli) with a [`LOCALSTACK_AUTH_TOKEN`](https://docs.localstack.cloud/getting-started/auth-token/) (required for Pro features)
39+
- [AWS CLI](https://docs.localstack.cloud/user-guide/integrations/aws-cli/) with the [`awslocal` wrapper](https://docs.localstack.cloud/user-guide/integrations/aws-cli/#localstack-aws-cli-awslocal)
40+
- [AWS CDK](https://docs.localstack.cloud/user-guide/integrations/aws-cdk/) with [`cdklocal` wrapper](https://github.com/localstack/aws-cdk-local) (**optional**)
41+
- [Python 3.11+](https://www.python.org/downloads/) & `pip` for testing and Lambda functions
42+
- [`make`](https://www.gnu.org/software/make/) (**optional**, but recommended for running the sample application)
3743

38-
## Start LocalStack
44+
## Installation
3945

40-
Start your LocalStack container with the following configuration:
46+
To run the sample application, you need to install the required dependencies.
4147

42-
```bash
43-
localstack start
48+
First, clone the repository:
49+
50+
```shell
51+
git clone https://github.com/localstack-samples/sample-serverless-quiz-app.git
4452
```
4553

46-
If you run into specific CORS issues, disable it using a [browser extension](https://webextension.org/listing/access-control.html).
54+
Then, navigate to the project directory:
4755

48-
## Local Deployment
56+
```shell
57+
cd sample-serverless-quiz-app
58+
```
4959

50-
### AWS CLI (`awslocal`)
60+
Create a virtual environment and install the testing dependencies:
5161

52-
To deploy the app locally, run the following command:
62+
```shell
63+
python -m venv .venv
64+
source .venv/bin/activate
65+
pip install -r tests/requirements-dev.txt
66+
```
5367

54-
```bash
55-
bash bin/deploy.sh
68+
## Deployment
69+
70+
Start LocalStack with the `LOCALSTACK_AUTH_TOKEN` pre-configured:
71+
72+
```shell
73+
localstack auth set-token <your-auth-token>
74+
localstack start
5675
```
57-
The output will be:
5876

59-
```bash
77+
### Option 1: AWS CLI Deployment (Recommended)
78+
79+
To deploy the complete application with all features, run:
80+
81+
```shell
82+
bin/deploy.sh
83+
```
84+
85+
The deployment output will show:
86+
87+
```shell
6088
CloudFront URL: https://1e372b81.cloudfront.localhost.localstack.cloud
6189
API Gateway Endpoint: http://localhost:4566/_aws/execute-api/4xu5emxibf/test
6290
```
6391

64-
Navigate to the CloudFront URL to check out the app. The script would also seed some quiz data and user data to make local testing easier.
92+
### Option 2: CDK Local Deployment
6593

66-
<!-- ### CDK (AWS)
94+
Alternatively, deploy using CDK with LocalStack:
6795

68-
To deploy the application to AWS, ensure your account is bootstraped via `cdk bootstrap` and then run
96+
```shell
97+
cd cdk
98+
cdklocal bootstrap
99+
AWS_CMD=awslocal CDK_CMD=cdklocal bash ../bin/deploy_cdk.sh
100+
```
69101

70-
```bash
71-
AWS_CMD=aws CDK_CMD=cdk bash ./bin/deploy_cdk.sh
72-
``` -->
102+
## Testing
73103

74-
### CDK Local
104+
The application includes comprehensive testing capabilities across multiple dimensions:
75105

76-
Alternatively the application can be deployed to LocalStack via `cdklocal`, our wrapper around the AWS CDK. Perform the following steps:
106+
### Manual Testing
77107

78-
1. Bootstrap LocalStack: `cd cdk && cdklocal bootstrap`
79-
2. Deploy the application: `AWS_CMD=awslocal CDK_CMD=cdklocal bash ./bin/deploy_cdk.sh`
108+
Navigate to the CloudFront URL from the deployment output to interact with the quiz application. The interface allows you to:
80109

81-
_Note: while the core quiz application works with CDK, additional features have not been implemented yet._
110+
- Create new quizzes with multiple choice questions
111+
- Submit quiz responses and receive immediate scoring
112+
- View leaderboards with top performers
113+
- Test email notifications through the MailHog extension
82114

83-
## Local Testing
115+
**Note**: If you have deployed the application using AWS CLI, sample quiz data would have been seeded to make local testing easier.
84116

85-
To run an automated test suite against the local deployment, run the following command:
117+
### End-to-End Integration Testing
86118

87-
```bash
88-
pip3 install -r tests/requirements-dev.txt
119+
Run the complete test suite to validate quiz creation, submission, and scoring:
120+
121+
```shell
89122
pytest tests/test_infra.py
90123
```
91124

92-
The automated tests utilize the AWS SDK for Python (boto3) and the `requests` library to interact with the Quiz App API. They automate the creation of quizzes, submission of answers, and retrieval of scores and leaderboard details to verify the app's functionality in an end-to-end manner.
125+
The automated tests utilize the AWS SDK for Python (boto3) and the `requests` library to interact with the quiz application API.
126+
127+
## Use Cases
93128

94-
## Stack Insights
129+
### Stack Insights
95130

96131
While testing your app infrastructure, you can retrieve detailed API telemetry over [Stack Insights](https://app.localstack.cloud/stacks). This includes:
97132

@@ -101,7 +136,7 @@ While testing your app infrastructure, you can retrieve detailed API telemetry o
101136
- Specific services called during the instance
102137
- Use the slide toggle to select a time period to view specific API calls
103138

104-
## Resource Browser
139+
### Resource Browser
105140

106141
You can use Resource Browser to inspect & manage some of the local resources, such as:
107142

@@ -111,7 +146,7 @@ You can use Resource Browser to inspect & manage some of the local resources, su
111146

112147
Click on the resources to inspect their configurations and observe how they operate locally with detailed granularity. You can view additional running services on the [Status Page](https://app.localstack.cloud/inst/default/status). With the exception of EventBridge Pipes and STS, resources for all other services are accessible in a unified view.
113148

114-
## Cloud Pods
149+
### Cloud Pods
115150

116151
To avoid deploying from scratch, you can setup the local development environment using Cloud Pods. To setup the entire stack using Cloud Pods, re-start your LocalStack container:
117152

@@ -134,7 +169,7 @@ echo "https://$DISTRIBUTION_ID.cloudfront.localhost.localstack.cloud"
134169

135170
Your app is now ready to be tested!
136171

137-
## Extensions
172+
### Extensions
138173

139174
After a quiz response is submitted, a Step Functions state machine triggers SES to send an email if an address is provided. To view the email, you can utilize the [LocalStack MailHog Extension](https://pypi.org/project/localstack-extension-mailhog/). Install the MailHog Extension through the [Extensions Manager](https://app.localstack.cloud/inst/default/extensions/manage) or by using the following command:
140175

@@ -150,11 +185,11 @@ Alternatively, you can inspect the SES Developer endpoint for emails in the foll
150185
curl -s http://localhost.localstack.cloud:4566/_aws/ses
151186
```
152187

153-
## Continuous Integration
188+
### Continuous Integration
154189

155-
For testing the app within the GitHub Actions workflow, you can refer to the provided workflow in [`integration-test.yml`](.github/workflows/integration-test.yml). This workflow utilizes the [`setup-localstack`](https://github.com/localstack/setup-localstack) action to start LocalStack, deploy the stack, execute tests, and perform final verification. Sample runs are available on the [Actions page](https://github.com/localstack-samples/serverless-quiz-app/actions/workflows/integration-test.yml).
190+
For testing the app within the GitHub Actions workflow, you can refer to the provided workflow in [`integration-test.yml`](.github/workflows/integration-test.yml). This workflow utilizes the [`setup-localstack`](https://github.com/localstack/setup-localstack) action to start LocalStack, deploy the stack, execute tests, and perform final verification. Sample runs are available on the [Actions page](https://github.com/localstack-samples/sample-serverless-quiz-app/actions/workflows/integration-test.yml).
156191

157-
## IAM Policy Stream
192+
### IAM Policy Stream
158193

159194
Visit the [IAM Policy Stream](https://app.localstack.cloud/inst/default/policy-stream) to view the permissions required for each API call. This feature enables you to explore and progressively enhance security as your application develops.
160195

@@ -176,7 +211,7 @@ Find the missing policy statements and fix the IAM Policy on the [IAM Resource B
176211

177212
Here is a [tutorial](https://blog.localstack.cloud/generating-testing-iam-policies-locally-with-localstack/) showcasing how you can do the above!
178213

179-
## Chaos Engineering
214+
### Chaos Engineering
180215

181216
To experiment with Chaos in your developer environment, visit the [Chaos Engineering dashboard](https://app.localstack.cloud/chaos-engineering). Here, you can inject various chaos scenarios, such as rendering the DynamoDB service unavailable in the `us-east-1` region or introducing a 90% occurrence of `ProvisionedThroughputExceededException` errors in your DynamoDB calls to observe how the application handles these disruptions.
182217

@@ -188,6 +223,8 @@ To test this pattern, execute the automated test suite with the following comman
188223
pytest tests/test_outage.py
189224
```
190225

226+
**Note**: The Chaos Engineering tests are designed to test the application's resilience during service outages. They use Chaos API to inject failures into the application. Chaos API is a [LocalStack Enterprise](https://localstack.cloud/enterprise/) feature.
227+
191228
## Ephemeral Instance
192229

193230
To launch a short-lived, encapsulated deployment of the application on a remote LocalStack instance, you can utilize LocalStack Ephemeral Instances. Execute the following command to create an instance, deploy the resources, and retrieve the application URL:
@@ -200,8 +237,29 @@ This setup process typically takes about 1-2 minutes. Each Ephemeral Instance wi
200237

201238
> Alternatively, you can initiate the Ephemeral Instance through the Web App and load the `serverless-quiz-app` Cloud Pod. Note that the frontend of the app depends on local backend APIs (`localhost:4566`) and will not function in this remote setup. Future enhancements are planned to address this limitation by allowing the injection of the Ephemeral Instance URL into resources using an environment variable.
202239
203-
You can utilize GitHub Actions to launch an Ephemeral Instance with your app stack deployed, facilitating Application Previews. The process is outlined in the [`preview.yml`](.github/workflows/preview.yml) file, which employs the [`setup-localstack`](https://github.com/localstack/setup-localstack) GitHub Action. For practical implementation, view a [sample pull request](https://github.com/localstack-samples/serverless-quiz-app/pull/3) that demonstrates how this setup can enhance collaboration and facilitate acceptance testing.
240+
You can utilize GitHub Actions to launch an Ephemeral Instance with your app stack deployed, facilitating Application Previews. The process is outlined in the [`preview.yml`](.github/workflows/preview.yml) file, which employs the [`setup-localstack`](https://github.com/localstack/setup-localstack) GitHub Action. For practical implementation, view a [sample pull request](https://github.com/localstack-samples/sample-serverless-quiz-app/pull/3) that demonstrates how this setup can enhance collaboration and facilitate acceptance testing.
241+
242+
## Summary
243+
244+
This sample application demonstrates how to build, deploy, and test a complete serverless quiz management platform using LocalStack's comprehensive development ecosystem. It showcases the following advanced patterns:
245+
246+
- Deploying complex event-driven serverless architectures with multiple AWS service integrations
247+
- Implementing robust error handling with Dead Letter Queues and retry mechanisms
248+
- Utilizing LocalStack's advanced platform features like Cloud Pods, Stack Insights, and Chaos Engineering
249+
- Integrating continuous testing and deployment workflows with GitHub Actions and Ephemeral Instances
250+
- Building production-ready IAM policies using Policy Stream for least-privilege access control
251+
- Implementing real-time notifications and email workflows with Step Functions and SES integration
252+
- Testing system resilience through controlled chaos engineering experiments
253+
254+
The application provides a comprehensive foundation for understanding enterprise serverless development patterns, advanced LocalStack platform capabilities, and production-ready cloud application architecture.
204255

205-
## License
256+
## Learn More
206257

207-
Apache License 2.0
258+
- [LocalStack Stack Insights](https://docs.localstack.cloud/user-guide/web-application/stack-insights/) for monitoring and telemetry
259+
- [LocalStack Cloud Pods](https://docs.localstack.cloud/user-guide/cloud-pods/) for state management and sharing
260+
- [LocalStack Chaos Engineering](https://docs.localstack.cloud/user-guide/chaos-engineering/) for resilience testing
261+
- [LocalStack Extensions](https://docs.localstack.cloud/user-guide/extensions/) for enhanced development workflows
262+
- [LocalStack IAM Policy Stream](https://docs.localstack.cloud/user-guide/iam-policy-stream/) for security policy development
263+
- [LocalStack GitHub Actions](https://docs.localstack.cloud/user-guide/ci/) for continuous integration
264+
- [LocalStack Ephemeral Instances](https://docs.localstack.cloud/user-guide/ci/ephemeral-instances/) for application previews
265+
- [AWS Step Functions with LocalStack](https://docs.localstack.cloud/aws/services/stepfunctions/) for workflow orchestration

0 commit comments

Comments
 (0)