Building a Serverless Quiz Application with LocalStack
Introduction
Section titled “Introduction”Interactive quiz applications are popular for education, training, and engagement platforms. Building them with serverless architecture provides scalability, cost-effectiveness, and simplified maintenance. In this tutorial, we’ll create a complete serverless quiz application using AWS Lambda, DynamoDB, and API Gateway.
Our quiz application will allow users to:
- Create new quizzes with multiple-choice questions
- Submit quiz responses and receive immediate scoring
- View quiz results and leaderboards
Using LocalStack, we can develop and test this entire serverless infrastructure locally before deploying to AWS, enabling rapid development cycles and cost-effective testing.
Prerequisites
Section titled “Prerequisites”For this tutorial, you will need:
- LocalStack Pro with a valid auth token
- AWS CLI with awslocalwrapper
- AWS CDK with cdklocalwrapper (optional)
- Python 3.11+ and pip
- curl for testing API endpoints
- make(optional, but recommended for running the sample application)
Architecture
Section titled “Architecture”The following diagram shows the serverless architecture we’ll build:

The architecture consists of:
- API Gateway: REST API endpoints for quiz operations with Lambda integrations
- Lambda Functions: Serverless functions handling quiz operations (create, submit, score, retrieve)
- DynamoDB Tables: NoSQL database storing quiz metadata (Quizzes) and user submissions (UserSubmissions)
- CloudFront Distribution: Global delivery of frontend assets with caching
- S3 Bucket: Static website hosting for the quiz frontend interface
- SQS: Managing asynchronous submissions with Dead Letter Queue for failed processing
- SNS Topics: Alert notifications and system integration
- Step Functions: Email notification workflows
- IAM Roles and Policies: Least-privilege access control for all services
Request Flow
Section titled “Request Flow”- Client sends HTTP requests to API Gateway endpoints
- API Gateway triggers corresponding Lambda functions
- Lambda functions interact with DynamoDB for data persistence
- Responses are returned through API Gateway to the client
- Static frontend is served from S3 bucket via CloudFront distribution
Getting Started
Section titled “Getting Started”Clone the Repository
Section titled “Clone the Repository”First, clone the sample repository and navigate to the project directory:
git clone https://github.com/localstack-samples/sample-serverless-quiz-app.gitcd sample-serverless-quiz-appSet up the Environment
Section titled “Set up the Environment”Create a Python virtual environment and install dependencies:
python -m venv .venvsource .venv/bin/activate  # On Windows: .venv\Scripts\activatepip install -r tests/requirements-dev.txtDeploying the Application
Section titled “Deploying the Application”Start LocalStack
Section titled “Start LocalStack”First, start LocalStack with your auth token:
localstack auth set-token <your-auth-token>localstack startDeploy the Infrastructure
Section titled “Deploy the Infrastructure”You can deploy the application using either AWS CLI or CDK:
Option 1: AWS CLI Deployment (Recommended)
Section titled “Option 1: AWS CLI Deployment (Recommended)”Deploy the complete serverless infrastructure using the provided script:
bin/deploy.shOption 2: CDK Deployment
Section titled “Option 2: CDK Deployment”Alternatively, deploy using AWS CDK with LocalStack:
cd cdkcdklocal bootstrapAWS_CMD=awslocal CDK_CMD=cdklocal bash ../bin/deploy_cdk.shBoth deployment methods will:
- Create DynamoDB tables for quizzes and submissions
- Deploy Lambda functions for quiz operations
- Set up API Gateway endpoints
- Configure S3 bucket for static hosting
- Seed sample quiz data
The deployment output will show:
CloudFront URL: https://1e372b81.cloudfront.localhost.localstack.cloudAPI Gateway Endpoint: http://localhost:4566/_aws/execute-api/4xu5emxibf/testTesting the Application
Section titled “Testing the Application”The application includes comprehensive testing capabilities across multiple dimensions:
Manual Testing
Section titled “Manual Testing”Navigate to the CloudFront URL from the deployment output to interact with the quiz application. The interface allows you to:
- Create new quizzes with multiple choice questions
- Submit quiz responses and receive immediate scoring
- View leaderboards with top performers
- Test email notifications through the MailHog extension
Note: If you have deployed the application using AWS CLI, sample quiz data would have been seeded to make local testing easier.
End-to-End Integration Testing
Section titled “End-to-End Integration Testing”Run the complete test suite to validate quiz creation, submission, and scoring:
pytest tests/test_infra.pyThe automated tests utilize the AWS SDK for Python (boto3) and the requests library to interact with the quiz application API.
Advanced Features with LocalStack Pro
Section titled “Advanced Features with LocalStack Pro”Resource Browser
Section titled “Resource Browser”Use the LocalStack Web Application to inspect your deployed resources:
- DynamoDB Tables: View table data and query operations
- Lambda Functions: Monitor function invocations and logs
- API Gateway: Inspect API endpoints and request routing
Cloud Pods for Quick Setup
Section titled “Cloud Pods for Quick Setup”Skip the deployment step by loading a pre-configured environment:
localstack restartlocalstack pod load serverless-quiz-appThis instantly loads the complete application infrastructure from a saved state.
Conclusion
Section titled “Conclusion”In this tutorial, we’ve built a complete serverless quiz application demonstrating key serverless patterns:
- Event-driven architecture with API Gateway triggering Lambda functions
- NoSQL data persistence using DynamoDB for scalable storage
- Stateless function design enabling automatic scaling
- RESTful API design for clean client-server communication
The application showcases how LocalStack enables rapid serverless development by providing a local AWS environment for testing and iteration. This approach allows developers to:
- Test serverless applications without cloud costs
- Develop offline with full AWS service emulation
- Validate application logic before production deployment
- Iterate quickly during development cycles
For production deployment, the same code and configuration can be deployed to AWS with minimal changes, demonstrating the power of LocalStack for serverless development workflows.