Code Monkey home page Code Monkey logo

node-aws-fargate-terraform's Introduction

AWS Fargate Node App

A reference project to deploy a Node Express app onto Amazon ECS on AWS Fargate with Terraform, inspired by this tutorial documentation

A microservice which creates, and authenticates users from a MongoDB database

AWS Architecture

Pre-requisite

  • Make sure you have installed Terraform, AWS CLI, and configured a default AWS CLI profile (see doc here)
terraform -help # prints Terraform options
which aws # prints /usr/local/bin/aws
aws --version # prints aws-cli/2.0.36 Python/3.7.4 Darwin/18.7.0 botocore/2.0.0
aws configure # configure your AWS CLI profile
  • You have created a database on MongoDB Atlas and have obtained a database connection string

Configuration

  • Create a Github project, and generate a personal access token (see doc here)

  • Create an S3 bucket to store Terraform state. Populate bucket name in 01-main.tf

  • Create a secret on AWS Secrets Manager named DockerHubAccessToken with key DOCKER_HUB_ACCESS_TOKEN, and your Docker access token as value

  • Create a secret on AWS Secrets Manager named MongoPassword with key MONGO_PASSWORD, and your MongoDB password as value

  • Populate terraform.tfvars:

default_region            = "us-east-1"
docker_username           = "matlau"
github_username           = "MatthewCYLau"
github_project_name       = "node-aws-fargate-terraform"
app_name                  = "node-aws-fargate-app"
environment               = "staging"
mongo_username            = "admin-matlau"
mongo_host                = "mattewcylau-5ltcp.mongodb.net"
mongo_database_name       = "node-aws-fargate-app"
mongo_password_secret_arn = <MongoPassword Secret ARN>

Deploy

cd deploy # change to deploy directory
terraform init # initialises Terraform
terraform apply # deploys AWS stack. See output for AWS loadbalancer DNS name
terraform destroy # destroys AWS stack

When prompted for github_token, provide the value and hit Return. Alternatively, create a local environment variable named TF_VAR_github_token

Usage

  • Create a user by making POST request to /api/users with the following JSON body:
{
  "email": "[email protected]",
  "password": "password",
  "name": "jondoe"
}
  • See Postman collection here

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

If you find this project helpful, please give a โญ or even better buy me a coffee โ˜• ๐Ÿ‘‡ because I'm a caffeine addict ๐Ÿ˜…

Buy Me A Coffee

License

MIT

node-aws-fargate-terraform's People

Contributors

matthewcylau avatar

Watchers

James Cloos avatar  avatar

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.