A vanilla express.js project in TypeScript. It provides a few simple RESTful API endpoints for demonstration purposes, nothing fancy.
diagram raw file (draw.io format): https://drive.google.com/file/d/1mlh_tGtY4NF3XTauX2NC_HOkPyb775gI/view?usp=sharing
# build the latest docker image, expose port 3000
docker build -t api-server:latest --build-arg PORT=3000 .
# run the docker image
docker run -d --rm --env-file .env -p 3000:3000 api-server:latest
# test GET /
curl http://localhost:3000
# you should see {"message":"server is up 🚀"}
-
make sure your command line has sufficient access to the target AWS account. recommend Configuring the AWS CLI to use AWS IAM Identity Center (successor to AWS Single Sign-On).
-
bootstrap CDK in the target AWS account, if it hasn't been done.
-
create an
.env
file by duplicating.env.template
, example:AWS_ACCOUNT=111222333444 AWS_REGION=ap-southeast-2 AWS_HOSTED_ZONE_DOMAIN=dev.example.com ENV=dev PORT=3000
-
make sure the root domain (
dev.example.com
in the example .env file) has been hosted as a Route53 public hosted zone, and its NS records can be resolved on the public internet.
npm install
npx lerna run deploy --scope=@capturedlabs/rest-api-ecs
I'm hosting it in my personal AWS account, be merciful 🙈
# GET / - health check
curl -X GET \
https://rest-api-ecs.dev.capturedlabs.com
# expected output:
# {"message":"server is up 🚀"}
# POST /users - create a user
curl -X POST \
-H "Content-Type: application/json" \
-d '{"username":"marten", "fullName": "Marten Trendle", "email": "[email protected]"}' \
https://rest-api-ecs.dev.capturedlabs.com/users
# PATCH /users/:username - update a user
curl -X PATCH \
-H "Content-Type: application/json" \
-d '{"address":"4 La Follette Pass"}' \
https://rest-api-ecs.dev.capturedlabs.com/users/marten
# GET /users/:username - get a user
curl -X GET \
https://rest-api-ecs.dev.capturedlabs.com/users/marten
# expected output:
# {"username":"marten","email":"[email protected]","fullName":"Marten Trendle","address":"4 La Follette Pass"}
To make things simple, I borrowed the example single table design from Alex Debrie's blog The What, Why, and When of Single-Table Design with DynamoDB. Choosing underlying database service is not the concern of this demo project. DynamoDB is chosen because of its on-demand pricing model.