Created
November 12, 2019 03:16
-
-
Save hoang-innomize/d9f4f9e5e7e9d9ba431b83366d293f59 to your computer and use it in GitHub Desktop.
An example of using AWS CDK to create a new VPC on AWS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as cdk from '@aws-cdk/core'; | |
import * as ec2 from '@aws-cdk/aws-ec2'; | |
export class NetworkStack extends cdk.Stack { | |
public readonly vpc: ec2.Vpc; | |
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) { | |
super(scope, id, props); | |
this.vpc = new ec2.Vpc(this, 'VPC', { | |
cidr: '10.0.0.0/16', | |
natGatewaySubnets: { | |
subnetName: 'Public' | |
}, | |
subnetConfiguration: [ | |
{ | |
cidrMask: 26, | |
name: 'Public', | |
subnetType: ec2.SubnetType.PUBLIC | |
}, | |
{ | |
name: 'Application', | |
subnetType: ec2.SubnetType.PRIVATE | |
}, | |
{ | |
cidrMask: 27, | |
name: 'Database', | |
subnetType: ec2.SubnetType.ISOLATED | |
} | |
] | |
}); | |
const vpcSecurityGroup = new ec2.SecurityGroup(this, 'SecurityGroup', { | |
vpc: this.vpc, | |
description: 'Allow ssh access to ec2 instances', | |
allowAllOutbound: true | |
}); | |
vpcSecurityGroup.addIngressRule( | |
ec2.Peer.anyIpv4(), | |
ec2.Port.tcp(22), | |
'allow ssh access from the world' | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment