An Express API to interact with AWS DynamoDB service written in TypeScript.
Use docker-compose.yml
file to launch local version of DynamoDB if you don't have access to AWS DynamoDB instance.
You might have to give permissions to ./docker/dynamodb
folder that local DynamoDB uses as data file. Use following command to do so -
chmod 777 -R ./docker/dynamodb
Once above steps have been taken care of, use below command to launch DynamoDB container locally -
docker-compose up
Next, to create a table (Movies
) locally, use the following command. This command uses year
as HASH/Primary key and title
as RANGE/Sort key.
aws dynamodb create-table --table-name Movies --attribute-definitions AttributeName=year,AttributeType=N AttributeName=title,AttributeType=S --key-schema AttributeName=year,KeyType=HASH AttributeName=title,KeyType=RANGE --provisioned-throughput ReadCapacityUnits=5,WriteCapacityUnits=5 --tags Key=Project,Value=movie-api --endpoint-url http://localhost:8000
To confirm if tables have been created, run the command below -
aws dynamodb list-tables --endpoint-url http://localhost:8000
Once you clone the project in your local machine, install npm
packages using npm ci
. And run the application using npm run start:dev
.
- Create (POST) a movie
curl -X POST -H "Content-Type: application/json" -d '{ "year": 2001, "title": "Rush" }' http://localhost:3000/api/v1/movies
- GET all movies
curl http://localhost:3000/api/v1/movies
- GET movies by year
curl http://localhost:3000/api/v1/movies/year/2001
- GET a movie by its year and title
curl http://localhost:3000/api/v1/movies/year/2001/title/Rush
- Update (PATCH) a movie
curl -X PATCH -H "Content-Type: application/json" -d '{ "year": 2002, "title": "Rush 2", "info": { "rating": 5 } }' http://localhost:3000/api/v1/movies