Server Infrastructure using AWS and CDK.
AWS CDK Infrastructure package that creates:
- Network Layer - Multi-AZ VPC with 3 subnets (1 public and 2 private-isolated)
- Data Layer - Postgres Aurora database cluster and a Redis elasticache cluster
- Service Layer - Fargate Service in an ECS cluster backed by an Application Load Balancer
- CICD Layer - CodePipeline with 4 stages and a manual intervention.
- Scripts - Scripts that assist in deploying and destroying
The infra sources are organized into the following files:
- package.json: Package dependencies for npm
- network-layer.ts: Construct to create a multi-AZ VPC with 1 public and 2 private isolated subnets.
- data-layer.ts: Construct to create a postgres aurora database cluster and a redis elasticache cluster.
- ec2-service-layer.ts: Construct to create an EC2 instance in an AutoScalingGroup fronted by an ApplicationLoadBalancer with a validated DNS certificate.
- fargate-service-layer.ts: Construct to create an ECS cluster with an ApplicationLoadBalancedFargateService and a validated DNS certificate.
- cicd-layer.ts: Construct to create a CodePipeline with a Source, CodeBuild, ManualApproval and ECSDeploy stages.
- stack.ts: Stack that creates above 4 constructs in the right order.
- init.sh Script to install node, cdk and npm dependencies
- bootstrap.sh Script to bootstrap CDK in a certain account and region.
- configure.sh Script to configure parameters and secrets in AWS.
- deploy.sh: Script to deploy the infrastructure in AWS
- destroy.sh: Script to destroy the infrastructure in AWS
- teardown.sh: Script to de-configure parameters, secrets and remove any remaining resources that CDK couldn't destroy.
- cleanup.sh: Script to remove dependencies and clean up infrastructure workspace
Install Homebrew
Download and install Homebrew:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Install nvm
Install latest version of nvm:
brew install nvm
Install any version of Node
Install latest version of node:
nvm install node
or any specific version of node:
nvm install 14.17.6
Configure AWS CLI
Follow the instructions from AWS CDK Getting Started to configure your AWS account
Initialize and deploy
To install and initialize your infra package, if not already done:
./init.sh
To bootstrap your CDK project in your AWS account and region:
./bootstrap.sh
To configure parameters and secrets necessary in AWS:
./configure.sh
To perform the deployment of your infrastructure in AWS:
./deploy.sh
Destroy and clean-up
To install and initialize your infra package, if not already done:./init.sh
To destroy your complete infrastructure in AWS:
./destroy.sh
To de-configure and teardown params, secrets and remaining infra in AWS:
./teardown.sh
To cleanup the infra package:
./cleanup.sh