Skip to content

CDK app with ecs and rds for servian tech challenge

Notifications You must be signed in to change notification settings

bazd/cdk-ecs-rds

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

35 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Servian Tech Challenge App

This repo contains code for provisioning the Servian Tech Challenge App into AWS using the AWS Cloud Development Kit (CDK)

High-Level Architecture

The CDK app provisions the following infrastructure in AWS, along with associated IAM roles, security groups and other dependant resources:

  • A VPC with private and public subnets
  • A Postgres RDS instance with multi-az enabled for the database
  • An auto-generated secret for the RDS database password
  • An ECS cluster with a load-balanced auto-scaled Fargate task to run the app container

Unfortunately I ran out of time to get the app fully working, but it does provision the infrastructure, create the database instance and serve the app from the ALB

How to deploy

Note: The deployment process was tested on Windows 10, but should also work on Mac and Linux

1. Prerequisites

  1. An AWS account for the infrastructure to be provisioned into (a single region is used)
  2. An IAM user with an access key for programmatic access. The user must have permission to provision the resources into AWS (the deployment process was developed and tested with AdministratorAccess permissions)
  3. Node.js installed (tested with 14.17.6) https://nodejs.org/en/download/
  4. AWS CLI v2 installed (tested with 2.0.26) https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html
  5. AWS CDK v1 installed (tested with 1.124.0) https://docs.aws.amazon.com/cdk/latest/guide/getting_started.html
  6. Python v3.x installed (tested with 3.9.5) https://www.python.org/downloads/
  7. Git installed and configured (tested with 2.23.0). https://gitforwindows.org/

2. Configure the AWS CLI

  1. Open a command prompt or terminal. It should stay open for all of the steps in this deployment guide
  2. Run aws configure
  3. When prompted, enter values for AWS Access Key ID and AWS Secret Access Key for the IAM user
  4. When prompted for Default region name, enter the region that you want to deploy the app into (the app was developed and tested in ap-southeast-2)
  5. When prompted for Default output format, press Enter

3. Clone the repo

Run the commands below to clone this repo locally

  1. git clone https://github.com/bazd/cdk-ecs-rds.git
  2. cd cdk-ecs-rds

4. Install Python requirements into virtual environment

Run the following commands according to the OS of the deployment environment

Windows

  1. python -m venv .venv
  2. .venv\scripts\activate.bat
  3. pip install -r requirements.txt

Mac / Linux:

  1. python -m venv .venv
  2. source .venv/bin/activate
  3. pip install -r requirements.txt

5. Deploy the app using CDK

  1. Run cdk synth
    1. This executes the app, which causes the resources defined in it to be translated into an AWS CloudFormation template locally
    2. A list of the resources to be created is displayed
  2. Run cdk deploy then enter y to confirm when prompted
    1. This provisions the resources into AWS using the automatically generated CloudFormation template
    2. The terminal window will display the status of the deployment of each resource
    3. You can optionally log in to the AWS Console and see that a CloudFormation stack has been created
  3. Wait for the deployment to complete - it should take about 10 mins
    1. When all resources have finished deploying, 2 outputs will be displayed. These are the Load Balancer DNS name and the Service URL, and can be used to connect to the app
    2. Copy the Service URL into a web browser to access the app front end. (Unfortunately the app is not fully functional, but you should see a _servian logo and a To Do heading)

How to delete

If you want to completely remove all resources, do the following:

  1. Run cdk destroy then y to confirm
  2. From the AWS console, manually delete any CloudWatch log groups with a prefix of TcaStack-TcaTask

Future improvements

Potential improvements that can be added as required

  • Support for multiple environments, with different config in each (eg no multi-az database in dev)
  • Split the CDK app into separate stacks for easier management (eg network, app and database stacks)
  • IAM deployment user with permissions restricted to the minimum required
  • CI/CD for deployment
  • Nice DNS cname record pointing to the ALB name
  • RDS storage autoscaling
  • The healthcheck settings for the ALB target group should be configured to use the /healthcheck/ endpoint and not the default /
  • Monitoring
  • The updatedb task should only be executed in a new environment and not with every deployment

Useful CDK commands

  • cdk ls list all stacks in the app
  • cdk synth emits the synthesized CloudFormation template
  • cdk deploy deploy this stack to your default AWS account/region
  • cdk diff compare deployed stack with current state
  • cdk docs open CDK documentation

About

CDK app with ecs and rds for servian tech challenge

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published