ryanhallcs / pager-org-api

CRUD Api: AWS ECS, Postgres DB, Cloudform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

pager-org-api

CRUD Api: AWS ECS, Postgres DB, Cloudform

Working deployment at: http://pager-org-api-1612248399.us-west-2.elb.amazonaws.com/ Sample queries:

Features

  1. Highly available CRUD API for Organizations written in JS using Hapi
  2. Request and DB schema level validation
  3. DI and IoC using inversify js
  4. JWT Authorization on all CRUD endpoints, not auth on /metrics and /api/v1/login endpoints
  5. Basic unit testing of services and controllers utilizing Hapi's .inject() functionality
  6. Postgres database
    1. sequelize ORM
    2. Migrations to create main table in /lib/migrations folder
    3. Indexes aligned with basic query patters of the search logic
      1. PK on id column, associated with /api/v1/organization/{id}
      2. Unique BTREE indexes on code and name columns for /api/v1/organization?code=code and /api/v1/organization?name=name endpoints
  7. Request level metrics available through /metrics
  8. Dockerized service, pushed to AWS ECR
  9. gulp building and task running with argument injection
    1. Build: gulp
    2. Run server with recomplication on saving: gulp serve
    3. Example of running on a different port and db credentials: gulp serve --serverPort=3000 --username=myuser --password=mypass
    4. Run tests: gulp test
  10. AWS Cloudformation setup
    1. Full stack within VPC
    2. Deployment to ECS - ECS deploys containers to and autoscaling group across 2 availability zones (AZ) in private subnets
    3. Postgres RDS deployed also within private subnet
    4. Logging in cloudwatch
    5. Requests from internet routed only to load balancer, outgoing requests routed through NATs in their respective public subnets in each AZ
    6. DB only allows connections from ECS containers (the API services)
    7. Rolling updates utilizing CF and ECS: aws cloudformation update-stack
    8. Custom implementation based off of this ref arch - modified to fit this application and DB

Notes

  • CloudFormation was chosen because I didn't plan on using a deployment service and it still fit my requirements of having a declarative, infrastructure-as-code structure. (In the past I've used Terraform for this)
  • Migrations are run on server startup, which is not a great pattern, but necessary since DB is not accessible to public and I didn't set up VPN infrastructure. Ideally they would be apart of the deploy process.
  • Javascript language specific patterns are not a strong suit of mine as I've never developed a service in JS. I'm hoping instead the concepts of development came across: SOLID principles, etc
  • Deployment was done locally but is not complicated and easily scriptable for a system like Jenkins or Gitlab-CI. It involves:
    1. Building and pushing docker container to ECR ``docker buildanddocker push```
    2. Updating /infra/cloudformation files on s3 aws s3 sync
    3. Running aws cloudformation update-stack and rolling service updates can be seen in cloudformation console (or by CLI if needed)

About

CRUD Api: AWS ECS, Postgres DB, Cloudform


Languages

Language:JavaScript 100.0%