You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
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.
-**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
33
35
34
36
## Prerequisites
35
37
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)
37
43
38
-
## Start LocalStack
44
+
## Installation
39
45
40
-
Start your LocalStack container with the following configuration:
46
+
To run the sample application, you need to install the required dependencies.
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:
80
109
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
82
114
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.
84
116
85
-
To run an automated test suite against the local deployment, run the following command:
117
+
### End-to-End Integration Testing
86
118
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
89
122
pytest tests/test_infra.py
90
123
```
91
124
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
93
128
94
-
## Stack Insights
129
+
###Stack Insights
95
130
96
131
While testing your app infrastructure, you can retrieve detailed API telemetry over [Stack Insights](https://app.localstack.cloud/stacks). This includes:
97
132
@@ -101,7 +136,7 @@ While testing your app infrastructure, you can retrieve detailed API telemetry o
101
136
- Specific services called during the instance
102
137
- Use the slide toggle to select a time period to view specific API calls
103
138
104
-
## Resource Browser
139
+
###Resource Browser
105
140
106
141
You can use Resource Browser to inspect & manage some of the local resources, such as:
107
142
@@ -111,7 +146,7 @@ You can use Resource Browser to inspect & manage some of the local resources, su
111
146
112
147
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.
113
148
114
-
## Cloud Pods
149
+
###Cloud Pods
115
150
116
151
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:
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:
140
175
@@ -150,11 +185,11 @@ Alternatively, you can inspect the SES Developer endpoint for emails in the foll
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).
156
191
157
-
## IAM Policy Stream
192
+
###IAM Policy Stream
158
193
159
194
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.
160
195
@@ -176,7 +211,7 @@ Find the missing policy statements and fix the IAM Policy on the [IAM Resource B
176
211
177
212
Here is a [tutorial](https://blog.localstack.cloud/generating-testing-iam-policies-locally-with-localstack/) showcasing how you can do the above!
178
213
179
-
## Chaos Engineering
214
+
###Chaos Engineering
180
215
181
216
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.
182
217
@@ -188,6 +223,8 @@ To test this pattern, execute the automated test suite with the following comman
188
223
pytest tests/test_outage.py
189
224
```
190
225
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
+
191
228
## Ephemeral Instance
192
229
193
230
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
200
237
201
238
> 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.
202
239
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.
204
255
205
-
## License
256
+
## Learn More
206
257
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