Code Monkey home page Code Monkey logo

parks-reso-api's Introduction

Parks Reservation - API

Associated repos:

Local Development

Prerequisites

DynamoDB Local

This project makes use of dynamodb-local for local development. You can start an instance of DyanmoDB using Docker.

docker run -d -p 8000:8000 --name dynamodb amazon/dynamodb-local -jar DynamoDBLocal.jar -sharedDb

AWS Credentials

The AWS credentials AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY must exist in your environment as environment variables or in the .aws credential file. These values are used by the aws-sdk to instantiate sdk objects.

You can provide any value for them when using dynamodb-local. Real values are needed when performing operations on remote AWS services such as generating CAPTCHA audio using AWS Polly.

Start Development Server

yarn install
yarn start

Once server starts, the API will be available at http://localhost:3000/api. The local server is also configured to seed some basic data from the data directory.

Create Lambda Packages

The Serverless Framework is setup to package Lambda functions into individual zip files which is then used by Terraform to deploy to AWS.

yarn build

Deployment Pipeline

Github Actions

On push to the Main branch, three actions run:

  1. Lint
  2. Unit Tests
  3. Deploy to dev

The deploy to dev orchestrates deployment to AWS dev.

Getting environment variables for Actions and Terraform

There are three places where secrets and variables are stored.

Github

The secrets stored in Github are required for the AWS configuration in Github actions. The variables are as follows:

  • AWS_ROLE_TO_ASSUME
  • AWS_ACCESS_KEY_ID
  • AWS_REGION
  • AWS_SECRET_ACCESS_KEY
  • TFC_TEAM_TOKEN

These secrets are permanent and will not have to be changed in the future.

Terraform

There are a few secrets and variables that must be stored in Terraform Cloud. This is because they are required for provider initilization. This initialization happens before we are able to get variables from Github so they cannot be passed from AWS Parameter store. The variables are as follows:

  • target_env
  • AWS_SECRET_ACCESS_KEY
  • AWS_ACCESS_KEY_ID
  • aws_region
  • target_aws_account_id

These variables and secrets are permanent and will not have to be changed in the future.

AWS Parameter Store

These variables are required by Github Actions as well as Terraform. The variables themselves are stored in AWS Parameter Store. These parameters are organized into four categories:

  • parks-reso-api/
  • parks-reso-admin/
  • parks-reso-public/
  • parks-reso-shared/

These variables are passed to Terraform Cloud in the following steps:

AWS Parameter Store -> Github -> Terragrunt -> *.auto.tfvars -> Terraform Cloud

If a variable must be updated, you must update it from AWS Parameter store.

AWS Parameter Store

API requires a JWT secret for emails to work. This secret is stored in Secret Manager on AWS. This allows for secret rotation. This secret is accessed by Terraform Cloud directly.

Install, zip and upload to S3

For each of the functions we must run yarn install. After that, each function directory is zipped up and uploaded to S3. These zips will then be pulled down by Terraform Cloud.

Terragrunt and Terraform Cloud

This creates several things in AWS:

  • DynamoDB
  • Cloudfront Distribution
  • Connections among S3, Cloudfront, DynamoDB and API Gateway.

Deploying to test and prod

Test pipeline is triggered by publishing a release that is marked as a pre-release.

Prod pipeline is triggered by removing the pre-release tag from a release.

Config service

Config service is used to alter frontend via DynamoDB. In Dynamo, an item with the PK and SK of config must exist. Within the attributes, you are able to set certain configurations such as KEYCLOAK_ENABLED, API_LOCATION, and debugMode.

This item is request by the front ends upon client connection.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.