/ecs-microservices-cdktf

AWS ECS Microservices built out with the CDK for Terraform

Primary LanguageTypeScript

AWS ECS Microservices with CDK for Terraform

This project creates a microservice architecture on AWS ECS Fargate with Datadog monitoring using the CDK for Terraform. It seeks to follow a familiar pattern used by vanilla Terraform projects - flat file structure, declarative paradigm, and simplicity.

The Architecture

ECS Microservices CDKTF

All services use Fake Service as placeholders. You can swap them out with your own containerized services. You will need to change around port configurations and security groups to afford your applications' needs.

Getting Started

For this you'll need 4 things:

  • AWS Account and Credentials
  • Terraform
  • Terraform Cloud Account
  • Node.js
  • CDKTF
  • Datadog Account and Credentials

Instructions below:

1. AWS Account and Credentials

AWS is used to host the infrastructure. Surprise.

  1. Have an AWS Account.

  2. Have the AWS CLI Installed.

  3. Create an AWS IAM User with Admin or Power User Permissions.

  • this user will only be used locally
  1. Configure the AWS CLI with the IAM User from Step 4.

2. Terraform, Terraform Cloud, and the CDK for Terraform

Terraform and CDKT for Terraform are used to provision the infrastructure. Terraform Cloud (free) is used to manage your state.

  1. Install HashiCorp Terraform.

  2. Install Node.js.

  3. Install the CDK for Terraform

  4. Sign up for Terraform Cloud

  • yo its free for 5 team members
  1. Create a Terraform Cloud Organization

  2. Log in to Terraform Cloud from the CLI

  • this will set the credentials locally for the CDKTF to work with it
  1. Export your Terraform Cloud Organization name as an environment variable:
# Don't forget to set this!  Used in main.ts @line 153
$ export CDKTF_ECS_TFC_ORGANIZATION="your TFC organization name"

3. DataDog Account and Credentials

Datadog is used for monitoring and alerts across your ECS Cluster and Services.

  1. Have a Datadog Account.

  2. Export your Datadog API and APP Keys as Environment Variables.

# Keys found and created in app.datadoghq.com -> organization settings 
# # -> api keys
# # -> application keys
$ export DD_API_KEY="<your_api_key>"
$ export DD_APP_KEY="<your_app_key>"

Deploying the Project

  1. Clone this repo.

  2. Run npm i to install all dependencies.

  3. Run cdktf synth to ensure no errors are occuring.

  4. Run cdktf deploy and accept the deployment.

  5. Grab the URL from your client_service_endpoint Terraform Output and visit it to see the application.

  6. Optionally add /ui to your client_service_endpoint to see a visualization of your services.

  7. Optionally visit your Datadog account to see your monitor and dashboard for cluster CPU usage.