A serverless Todo API built with AWS Chalice, using DynamoDB for storage and deployed with CloudFormation.
- Create, read, update, and delete Todo items
- Serverless architecture using AWS Lambda and API Gateway
- Data persistence with Amazon DynamoDB
- Infrastructure as Code using CloudFormation
- Python 3.7 or higher
- AWS CLI configured with appropriate credentials
- AWS account with permissions to create Lambda, API Gateway, IAM roles, and DynamoDB resources
- Clone this repository
- Install dependencies:
pip install -r requirements.txtTo run the application locally:
chalice localThis will start a local development server at http://localhost:8000.
To deploy the application to AWS:
./deploy.shThis will:
- Generate the Chalice CloudFormation template
- Merge it with the additional resources defined in
aws_stack.yaml - Deploy the merged stack to AWS
- Output the API endpoint URL and DynamoDB table name
The application uses a separate CloudFormation template (aws_stack.yaml) to define additional resources:
- DynamoDB table for storing Todo items
This template is merged with the Chalice-generated template during deployment using Chalice's built-in --merge-template option.
To generate a CloudFormation template without deploying:
chalice package --stage dev --merge-template aws_stack.yaml --template-format json .chalice/cloudformationThis will create a merged CloudFormation template in the .chalice/cloudformation directory that you can deploy using the AWS CloudFormation console or AWS CLI.
To deploy using the merged CloudFormation template:
aws cloudformation deploy --template-file .chalice/cloudformation/sam.json --stack-name todo-app --capabilities CAPABILITY_IAMGET /- Get API informationGET /todos- List all todosPOST /todos- Create a new todoGET /todos/{todo_id}- Get a specific todoPUT /todos/{todo_id}- Update a todoDELETE /todos/{todo_id}- Delete a todo
curl -X POST https://your-api-id.execute-api.region.amazonaws.com/api/todos \
-H "Content-Type: application/json" \
-d '{"title": "Learn AWS Chalice", "description": "Build a serverless API with Chalice"}'curl https://your-api-id.execute-api.region.amazonaws.com/api/todoscurl https://your-api-id.execute-api.region.amazonaws.com/api/todos/{todo_id}curl -X PUT https://your-api-id.execute-api.region.amazonaws.com/api/todos/{todo_id} \
-H "Content-Type: application/json" \
-d '{"title": "Updated title", "completed": true}'curl -X DELETE https://your-api-id.execute-api.region.amazonaws.com/api/todos/{todo_id}To remove all AWS resources created by this application:
chalice deleteOr if you deployed using CloudFormation:
aws cloudformation delete-stack --stack-name todo-app