Skip to content

AWS CDK IaC to create a new VPC with subnets, and create an EC2 AutoScalingGroup behind an ALB

Notifications You must be signed in to change notification settings

jojo786/aws-cdk-vpc-ec2-alb-asg

Repository files navigation

Create VPC, EC2 ASG, and RDS instance with AWS CDK Python

This is a project to create a new VPC, EC2 Auto Scaling group, Load Balancers and RDS instance on AWS with the AWS Cloud Development Kit.

This project:

  • Create VPC in 5 tier layers of subnets: PUBLIC, PRIVATE and ISOLATED, you can specify the number of AZs and the CIDR.
  • Create instance and NAT Gateway
  • Create ALB, EC2 Autoscaling group with scaling policy, and custom EBS volume
  • Create RDS instance (MySQL multi-AZ or Aurora)
  • Create security group and allow access from the other security group:
  • Using customized EC2 user data and specifying generated AMI properties with no need to specify the AMI id in every region

Architecture

Architecture

You can use cdk-dia to automatically produce an architecture diagram directly from CDK: cdk-dia

AWS Cloud Development Kit (AWS CDK)

The AWS Cloud Development Kit (AWS CDK) is an open-source software development framework to define cloud infrastructure in code and provision it through AWS CloudFormation.

It offers a high-level object-oriented abstraction to define AWS resources imperatively using the power of modern programming languages. Using the CDK’s library of infrastructure constructs, you can easily encapsulate AWS best practices in your infrastructure definition and share it without worrying about boilerplate logic.

Getting Started

For a detailed walkthrough, see the tutorial in the AWS CDK Developer Guide.

At a glance

Install or update the [AWS CDK CLI] from npm (requires Node.js ≥ 14.15.0). We recommend using a version in Active LTS

npm i -g aws-cdk

Useful 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

Examples

https://github.com/aws-samples/aws-cdk-examples contains a set of example projects for the AWS Cloud Development Kit.

Its the official list of CDK example code. The repo is subdivided into sections for each language (see "Examples"). Each language has its own subsection of examples with the ultimate aim of complete language parity (same subset of examples exist in each language). These examples each provide a demonstration of a common service implementation, or infrastructure pattern that could be useful in your use of the CDK for building your own infrastructure. This repo contains examples in each language supported by the CDK. Some languages are fully supported by JSII, but as additional languages are added, you will see those marked as Developer Preview. You can find the examples for each of those languages at the following links:

Language JSII Language-Stability
Typescript Examples Stable
Python Examples Stable
.NET Examples Stable
Java Examples Stable
Go Examples Stable

Learning Resources

While this is an excellent learning resource for the CDK, there are other resources that can be referenced to assist with your learning/development process.

Official Resources

About

AWS CDK IaC to create a new VPC with subnets, and create an EC2 AutoScalingGroup behind an ALB

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages