Skip to content
Get Started for Free

Building a Serverless Quiz Application with LocalStack

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.

For this tutorial, you will need:

The following diagram shows the serverless architecture we’ll build:

Application Architecture

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
  1. Client sends HTTP requests to API Gateway endpoints
  2. API Gateway triggers corresponding Lambda functions
  3. Lambda functions interact with DynamoDB for data persistence
  4. Responses are returned through API Gateway to the client
  5. Static frontend is served from S3 bucket via CloudFront distribution

First, clone the sample repository and navigate to the project directory:

Terminal window
git clone https://github.com/localstack-samples/sample-serverless-quiz-app.git
cd sample-serverless-quiz-app

Create a Python virtual environment and install dependencies:

Terminal window
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install -r tests/requirements-dev.txt

First, start LocalStack with your auth token:

Terminal window
localstack auth set-token <your-auth-token>
localstack start

You can deploy the application using either AWS CLI or CDK:

Section titled “Option 1: AWS CLI Deployment (Recommended)”

Deploy the complete serverless infrastructure using the provided script:

Terminal window
bin/deploy.sh

Alternatively, deploy using AWS CDK with LocalStack:

Terminal window
cd cdk
cdklocal bootstrap
AWS_CMD=awslocal CDK_CMD=cdklocal bash ../bin/deploy_cdk.sh

Both deployment methods will:

  1. Create DynamoDB tables for quizzes and submissions
  2. Deploy Lambda functions for quiz operations
  3. Set up API Gateway endpoints
  4. Configure S3 bucket for static hosting
  5. Seed sample quiz data

The deployment output will show:

Terminal window
CloudFront URL: https://1e372b81.cloudfront.localhost.localstack.cloud
API Gateway Endpoint: http://localhost:4566/_aws/execute-api/4xu5emxibf/test

The application includes comprehensive testing capabilities across multiple dimensions:

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.

Run the complete test suite to validate quiz creation, submission, and scoring:

Terminal window
pytest tests/test_infra.py

The automated tests utilize the AWS SDK for Python (boto3) and the requests library to interact with the quiz application API.

Use the LocalStack Web Application to inspect your deployed resources:

Skip the deployment step by loading a pre-configured environment:

Terminal window
localstack restart
localstack pod load serverless-quiz-app

This instantly loads the complete application infrastructure from a saved state.

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.