mamun67 / axis-terraform-flask

React / Flask template for AWS using Terraform

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

axis-terraform-flask

Boilerplate for a project using React frontend with a Terraform controlled backend API.

Tech

  • Cloud - AWS ECS Fargate, Cloudfront, Route53, SSL Certificate
  • API - Flask, Celery, Websockets
  • Frontend - React

Tools

  • Docker - Container developer environment
  • Terraform - Cloud infrastructure
  • direnv - Environment variable management
  • jq - JSON cli processor

AWS Terraform Creation

Configure Environment

Setup domain that is already registered in AWS Route53 in env.dist:

export PROJECT_DOMAIN="example.com"

Bootstrap Terraform setup

Create AWS Terraform shared environment for shared state locking. The file backend_config.tf is generated with Terraform setup information. NOTE:

Run from the terraform directory

$ cd terraform
terraform $ make bootstrap

Create AWS Infrastructure

Terraform will create all the necessary resources on AWS. Environment variables will be saved to the file aws.env, and the environment will need to be refreshed after running this step.

NOTE: Run from the terraform directory

$ cd terraform
$ make init 
$ make plan 
$ make apply

If you recieve InvalidViewerCertificate the first time your run plan/apply, run terraform plan apply process a second time. The SSL certificate needs to be validated when created and takes a bit of time.

$ make plan apply

Site Deploy

Deploy the backend containers to the ECR and update the two services. NOTE: Run from the root directory of the project

$ dist-backend-build
$ dist-backend-deploy

Deploy the frontend react app to a serverless cloudfront distribution

$ dist-frontend-build
$ dist-frontend-deploy

Get coffee...

Destroy backend

Tear down and remove all AWS infastructure components. NOTE: Run from the Terraform directory

$ cd terraform
$ make destroy

Get coffee...

About

React / Flask template for AWS using Terraform

License:MIT License


Languages

Language:HCL 48.4%Language:HTML 14.7%Language:JavaScript 12.5%Language:Python 8.9%Language:Makefile 8.0%Language:Dockerfile 4.0%Language:CSS 1.7%Language:Shell 1.3%Language:Smarty 0.5%