Download lib/vpc-stack.ts from Jessedbrown/Everyrealm-AWS-CDK: direct link, hf CLI and curl.
- Browser
- Download file 1.65 kB
-
https://huggingface.co/Jessedbrown/Everyrealm-AWS-CDK/resolve/main/lib/vpc-stack.ts
- Command line
-
hf download hf://Jessedbrown/Everyrealm-AWS-CDK/lib/vpc-stack.ts
-
curl -L -o vpc-stack.ts https://huggingface.co/Jessedbrown/Everyrealm-AWS-CDK/resolve/main/lib/vpc-stack.ts
1.65 kB
| import * as cdk from 'aws-cdk-lib'; | |
| import * as ec2 from 'aws-cdk-lib/aws-ec2'; | |
| import { Construct } from 'constructs'; | |
| // TODO: Add a VPC stack that can be used by all other stacks | |
| export class VpcStack extends cdk.Stack { | |
| public readonly vpc: ec2.Vpc; | |
| constructor(scope: Construct, id: string, props?: cdk.StackProps) { | |
| super(scope, id, props); | |
| // Create VPC | |
| this.vpc = new ec2.Vpc(this, 'BonusAppVpc', { | |
| maxAzs: 2, | |
| natGateways: 2, | |
| subnetConfiguration: [ | |
| { | |
| name: 'Public', | |
| subnetType: ec2.SubnetType.PUBLIC, | |
| cidrMask: 24, | |
| }, | |
| { | |
| name: 'Private', | |
| subnetType: ec2.SubnetType.PRIVATE_WITH_EGRESS, | |
| cidrMask: 24, | |
| }, | |
| ], | |
| }); | |
| // Let CloudFormation use the exact same resource names as before | |
| // No need to override logical ID as we're using the exact same name 'BonusAppVpc' | |
| // that will generate 'BonusAppVpcC5D8AE3E' in CloudFormation | |
| // Add outputs | |
| new cdk.CfnOutput(this, 'VpcId', { | |
| value: this.vpc.vpcId, | |
| description: 'The ID of the VPC', | |
| exportName: `${this.stackName}-VpcId`, | |
| }); | |
| new cdk.CfnOutput(this, 'PublicSubnets', { | |
| value: this.vpc.publicSubnets.map(subnet => subnet.subnetId).join(','), | |
| description: 'The IDs of the public subnets', | |
| exportName: `${this.stackName}-PublicSubnets`, | |
| }); | |
| new cdk.CfnOutput(this, 'PrivateSubnets', { | |
| value: this.vpc.privateSubnets.map(subnet => subnet.subnetId).join(','), | |
| description: 'The IDs of the private subnets', | |
| exportName: `${this.stackName}-PrivateSubnets`, | |
| }); | |
| } | |
| } | |