This project demonstrates how to develop a serverless backend for an event management system using AWS Lambda, DynamoDB, and S3 with the Serverless Framework. The backend is developed and tested locally using Localstack.
Ensure you have Node.js installed. Then, install the Serverless Framework globally:
npm install -g serverless
Create a new Serverless project:
serverless create --template aws-nodejs --path event-management-system
cd event-management-system
npm init -y
npm install aws-sdk serverless-offline serverless-localstack
Update your serverless.yml
to configure DynamoDB and S3 locally using Localstack, and include serverless-offline for local API Gateway.
See the full serverless.yml
configuration here.
Create a handler.js
file with the Lambda functions to handle the API endpoints. You can find the implementation details here.
Start Localstack:
localstack start
Create DynamoDB Table and S3 Bucket Locally:
aws --endpoint-url=http://localhost:4566 dynamodb create-table --table-name event-management-system-events --attribute-definitions AttributeName=id,AttributeType=S --key-schema AttributeName=id,KeyType=HASH --provisioned-throughput ReadCapacityUnits=1,WriteCapacityUnits=1 --region us-east-1
aws --endpoint-url=http://localhost:4566 s3api create-bucket --bucket event-management-system-uploads --region us-east-1
Start the Serverless Offline plugin to run the API locally:
serverless offline --stage local
Use Postman or curl to test the endpoints locally:
curl -X POST http://localhost:3000/local/events -H "Content-Type: application/json" -d '{"title":"Sample Event","description":"This is a sample event.","date":"2024-05-20"}'
curl http://localhost:3000/local/events
curl http://localhost:3000/local/events/{id}
curl -X PUT http://localhost:3000/local/events/{id} -H "Content-Type: application/json" -d '{"title":"Updated Event","description":"This is an updated event.","date":"2024-06-20"}'
curl -X DELETE http://localhost:3000/local/events/{id}