Skip to content

Latest commit

 

History

History
93 lines (64 loc) · 3.43 KB

File metadata and controls

93 lines (64 loc) · 3.43 KB

Simple REST API server powered by AWS ECS with Fargate

A vanilla express.js project in TypeScript. It provides a few simple RESTful API endpoints for demonstration purposes, nothing fancy.

Contents

Solution Architecture

diagram raw file (draw.io format): https://drive.google.com/file/d/1mlh_tGtY4NF3XTauX2NC_HOkPyb775gI/view?usp=sharing

Local Development

# 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 🚀"}

Manual Deployment

  npm install
  npx lerna run deploy --scope=@capturedlabs/rest-api-ecs

Live API Endpoints

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"}

Database Schema

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.