AWS Cloud Developement Kit : VPC編#1

AWS Cloud Developement Kit : VPC編#1:

AWS Cloud Development Kit (以下CDK)はプログラミング言語を使用してAWS環境の定義、デプロイができるフレームワークです。CDKのコードは最終的にCloudFormationのテンプレートに変換されてデプロイされるため、宣言型のCloudFormationの持つ冪等性(繰り返し実行しても同じ結果になる)の恩恵を受けつつ、様々なデータ構造や繰り返しなどの制御構造を持つプログラミング言語でインフラストラクチャを記述できるというメリットがあります。2019/1/20時点ではDeveloper Previewで、C#/JavaScript/TypeScript/Javaで記述することができます。

今回はTypeScriptでVPCを作成します。


環境

  • OS: macOS Sierra (10.12.6)
  • AWS CDK: 0.22.0

    基本的にはNode.jsが動く環境であればどの環境でも動作するはずです。


前提条件

以下は予めインストールしておく必要があります。


CDKプロジェクトの初期化

CDKプロジェクトをデフォルトテンプレートから初期化します。

  • CDKをアップデートします。
$ npm -g update aws-cdk 
$ cdk --version 
0.22.0 (build 644ebf5) 
  • プロジェクトフォルダを作成します。
$ mkdir aws-cdk-vpc-sample 
$ cd aws-cdk-vpc-sample 
  • プロジェクトを初期化します。
$ cdk init --language typescript 


プロパティ指定なしで VPCを作成する。

プロパティを一切指定せずにVPCを作成します。


  • @aws-cdk/aws-ec2パッケージをインストールします。
$ npm install @aws-cdk/aws-ec2 

  • lib/aws-cdk-vpc-sample.tsを編集し、VPCをスタックに追加します。
import cdk = require('@aws-cdk/cdk'); 
import ec2 = require('@aws-cdk/aws-ec2');  //ec2モジュールをインポート 
 
export class AwsCdkVpcSampleStack extends cdk.Stack { 
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { 
    super(scope, id, props); 
 
    new ec2.VpcNetwork(this, 'VPC');   //VPCを追加 
  } 
} 
  • ビルドします。
$ npm run build 

  • cdk diffコマンドを実行すると作成されるリソースが表示されます。
    AWSクレデンシャルとデフォルトリージョンが設定されていないとエラーになります。
$ cdk diff 
Resources 
[+] AWS::EC2::VPC VPC VPCB9E5F0B4 
[+] AWS::EC2::Subnet VPC/PublicSubnet1/Subnet VPCPublicSubnet1SubnetB4246D30 
[+] AWS::EC2::RouteTable VPC/PublicSubnet1/RouteTable VPCPublicSubnet1RouteTableFEE4B781 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/PublicSubnet1/RouteTableAssociation VPCPublicSubnet1RouteTableAssociation0B0896DC 
[+] AWS::EC2::Route VPC/PublicSubnet1/DefaultRoute VPCPublicSubnet1DefaultRoute91CEF279 
[+] AWS::EC2::EIP VPC/PublicSubnet1/EIP VPCPublicSubnet1EIP6AD938E8 
[+] AWS::EC2::NatGateway VPC/PublicSubnet1/NATGateway VPCPublicSubnet1NATGatewayE0556630 
[+] AWS::EC2::Subnet VPC/PublicSubnet2/Subnet VPCPublicSubnet2Subnet74179F39 
[+] AWS::EC2::RouteTable VPC/PublicSubnet2/RouteTable VPCPublicSubnet2RouteTable6F1A15F1 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/PublicSubnet2/RouteTableAssociation VPCPublicSubnet2RouteTableAssociation5A808732 
[+] AWS::EC2::Route VPC/PublicSubnet2/DefaultRoute VPCPublicSubnet2DefaultRouteB7481BBA 
[+] AWS::EC2::EIP VPC/PublicSubnet2/EIP VPCPublicSubnet2EIP4947BC00 
[+] AWS::EC2::NatGateway VPC/PublicSubnet2/NATGateway VPCPublicSubnet2NATGateway3C070193 
[+] AWS::EC2::Subnet VPC/PublicSubnet3/Subnet VPCPublicSubnet3Subnet631C5E25 
[+] AWS::EC2::RouteTable VPC/PublicSubnet3/RouteTable VPCPublicSubnet3RouteTable98AE0E14 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/PublicSubnet3/RouteTableAssociation VPCPublicSubnet3RouteTableAssociation427FE0C6 
[+] AWS::EC2::Route VPC/PublicSubnet3/DefaultRoute VPCPublicSubnet3DefaultRouteA0D29D46 
[+] AWS::EC2::EIP VPC/PublicSubnet3/EIP VPCPublicSubnet3EIPAD4BC883 
[+] AWS::EC2::NatGateway VPC/PublicSubnet3/NATGateway VPCPublicSubnet3NATGatewayD3048F5C 
[+] AWS::EC2::Subnet VPC/PrivateSubnet1/Subnet VPCPrivateSubnet1Subnet8BCA10E0 
[+] AWS::EC2::RouteTable VPC/PrivateSubnet1/RouteTable VPCPrivateSubnet1RouteTableBE8A6027 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/PrivateSubnet1/RouteTableAssociation VPCPrivateSubnet1RouteTableAssociation347902D1 
[+] AWS::EC2::Route VPC/PrivateSubnet1/DefaultRoute VPCPrivateSubnet1DefaultRouteAE1D6490 
[+] AWS::EC2::Subnet VPC/PrivateSubnet2/Subnet VPCPrivateSubnet2SubnetCFCDAA7A 
[+] AWS::EC2::RouteTable VPC/PrivateSubnet2/RouteTable VPCPrivateSubnet2RouteTable0A19E10E 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/PrivateSubnet2/RouteTableAssociation VPCPrivateSubnet2RouteTableAssociation0C73D413 
[+] AWS::EC2::Route VPC/PrivateSubnet2/DefaultRoute VPCPrivateSubnet2DefaultRouteF4F5CFD2 
[+] AWS::EC2::Subnet VPC/PrivateSubnet3/Subnet VPCPrivateSubnet3Subnet3EDCD457 
[+] AWS::EC2::RouteTable VPC/PrivateSubnet3/RouteTable VPCPrivateSubnet3RouteTable192186F8 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/PrivateSubnet3/RouteTableAssociation VPCPrivateSubnet3RouteTableAssociationC28D144E 
[+] AWS::EC2::Route VPC/PrivateSubnet3/DefaultRoute VPCPrivateSubnet3DefaultRoute27F311AE 
[+] AWS::EC2::InternetGateway VPC/IGW VPCIGWB7E252D3 
[+] AWS::EC2::VPCGatewayAttachment VPC/VPCGW VPCVPCGW99B986DC 
何も指定しなくてもVPC/Public Subnet x 3AZ/Private Subnet x 3AZ/Route Table/NATGW/IGWが作成されることがわかります。

  • CDKによって作成されるCloudFormationスタックのテンプレート(Resources)を確認します。
$ cdk synth AwsCdkVpcSampleStack 
Resources: 
  VPCB9E5F0B4: 
    Type: AWS::EC2::VPC 
    Properties: 
      CidrBlock: 10.0.0.0/16 
      EnableDnsHostnames: true 
      EnableDnsSupport: true 
      InstanceTenancy: default 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/Resource 
  VPCPublicSubnet1SubnetB4246D30: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.0.0/19 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1a 
      MapPublicIpOnLaunch: true 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet1 
        - Key: aws-cdk:subnet-name 
          Value: Public 
        - Key: aws-cdk:subnet-type 
          Value: Public 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet1/Subnet 
  VPCPublicSubnet1RouteTableFEE4B781: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet1/RouteTable 
  VPCPublicSubnet1RouteTableAssociation0B0896DC: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCPublicSubnet1RouteTableFEE4B781 
      SubnetId: 
        Ref: VPCPublicSubnet1SubnetB4246D30 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet1/RouteTableAssociation 
  VPCPublicSubnet1DefaultRoute91CEF279: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCPublicSubnet1RouteTableFEE4B781 
      DestinationCidrBlock: 0.0.0.0/0 
      GatewayId: 
        Ref: VPCIGWB7E252D3 
    DependsOn: 
      - VPCVPCGW99B986DC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet1/DefaultRoute 
  VPCPublicSubnet1EIP6AD938E8: 
    Type: AWS::EC2::EIP 
    Properties: 
      Domain: vpc 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet1/EIP 
  VPCPublicSubnet1NATGatewayE0556630: 
    Type: AWS::EC2::NatGateway 
    Properties: 
      AllocationId: 
        Fn::GetAtt: 
          - VPCPublicSubnet1EIP6AD938E8 
          - AllocationId 
      SubnetId: 
        Ref: VPCPublicSubnet1SubnetB4246D30 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet1/NATGateway 
  VPCPublicSubnet2Subnet74179F39: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.32.0/19 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1c 
      MapPublicIpOnLaunch: true 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet2 
        - Key: aws-cdk:subnet-name 
          Value: Public 
        - Key: aws-cdk:subnet-type 
          Value: Public 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet2/Subnet 
  VPCPublicSubnet2RouteTable6F1A15F1: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet2 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet2/RouteTable 
  VPCPublicSubnet2RouteTableAssociation5A808732: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCPublicSubnet2RouteTable6F1A15F1 
      SubnetId: 
        Ref: VPCPublicSubnet2Subnet74179F39 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet2/RouteTableAssociation 
  VPCPublicSubnet2DefaultRouteB7481BBA: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCPublicSubnet2RouteTable6F1A15F1 
      DestinationCidrBlock: 0.0.0.0/0 
      GatewayId: 
        Ref: VPCIGWB7E252D3 
    DependsOn: 
      - VPCVPCGW99B986DC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet2/DefaultRoute 
  VPCPublicSubnet2EIP4947BC00: 
    Type: AWS::EC2::EIP 
    Properties: 
      Domain: vpc 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet2/EIP 
  VPCPublicSubnet2NATGateway3C070193: 
    Type: AWS::EC2::NatGateway 
    Properties: 
      AllocationId: 
        Fn::GetAtt: 
          - VPCPublicSubnet2EIP4947BC00 
          - AllocationId 
      SubnetId: 
        Ref: VPCPublicSubnet2Subnet74179F39 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet2 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet2/NATGateway 
  VPCPublicSubnet3Subnet631C5E25: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.64.0/19 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1d 
      MapPublicIpOnLaunch: true 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet3 
        - Key: aws-cdk:subnet-name 
          Value: Public 
        - Key: aws-cdk:subnet-type 
          Value: Public 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet3/Subnet 
  VPCPublicSubnet3RouteTable98AE0E14: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet3/RouteTable 
  VPCPublicSubnet3RouteTableAssociation427FE0C6: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCPublicSubnet3RouteTable98AE0E14 
      SubnetId: 
        Ref: VPCPublicSubnet3Subnet631C5E25 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet3/RouteTableAssociation 
  VPCPublicSubnet3DefaultRouteA0D29D46: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCPublicSubnet3RouteTable98AE0E14 
      DestinationCidrBlock: 0.0.0.0/0 
      GatewayId: 
        Ref: VPCIGWB7E252D3 
    DependsOn: 
      - VPCVPCGW99B986DC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet3/DefaultRoute 
  VPCPublicSubnet3EIPAD4BC883: 
    Type: AWS::EC2::EIP 
    Properties: 
      Domain: vpc 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet3/EIP 
  VPCPublicSubnet3NATGatewayD3048F5C: 
    Type: AWS::EC2::NatGateway 
    Properties: 
      AllocationId: 
        Fn::GetAtt: 
          - VPCPublicSubnet3EIPAD4BC883 
          - AllocationId 
      SubnetId: 
        Ref: VPCPublicSubnet3Subnet631C5E25 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PublicSubnet3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PublicSubnet3/NATGateway 
  VPCPrivateSubnet1Subnet8BCA10E0: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.96.0/19 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1a 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PrivateSubnet1 
        - Key: aws-cdk:subnet-name 
          Value: Private 
        - Key: aws-cdk:subnet-type 
          Value: Private 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet1/Subnet 
  VPCPrivateSubnet1RouteTableBE8A6027: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PrivateSubnet1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet1/RouteTable 
  VPCPrivateSubnet1RouteTableAssociation347902D1: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCPrivateSubnet1RouteTableBE8A6027 
      SubnetId: 
        Ref: VPCPrivateSubnet1Subnet8BCA10E0 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet1/RouteTableAssociation 
  VPCPrivateSubnet1DefaultRouteAE1D6490: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCPrivateSubnet1RouteTableBE8A6027 
      DestinationCidrBlock: 0.0.0.0/0 
      NatGatewayId: 
        Ref: VPCPublicSubnet1NATGatewayE0556630 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet1/DefaultRoute 
  VPCPrivateSubnet2SubnetCFCDAA7A: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.128.0/19 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1c 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PrivateSubnet2 
        - Key: aws-cdk:subnet-name 
          Value: Private 
        - Key: aws-cdk:subnet-type 
          Value: Private 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet2/Subnet 
  VPCPrivateSubnet2RouteTable0A19E10E: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PrivateSubnet2 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet2/RouteTable 
  VPCPrivateSubnet2RouteTableAssociation0C73D413: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCPrivateSubnet2RouteTable0A19E10E 
      SubnetId: 
        Ref: VPCPrivateSubnet2SubnetCFCDAA7A 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet2/RouteTableAssociation 
  VPCPrivateSubnet2DefaultRouteF4F5CFD2: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCPrivateSubnet2RouteTable0A19E10E 
      DestinationCidrBlock: 0.0.0.0/0 
      NatGatewayId: 
        Ref: VPCPublicSubnet2NATGateway3C070193 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet2/DefaultRoute 
  VPCPrivateSubnet3Subnet3EDCD457: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.160.0/19 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1d 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PrivateSubnet3 
        - Key: aws-cdk:subnet-name 
          Value: Private 
        - Key: aws-cdk:subnet-type 
          Value: Private 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet3/Subnet 
  VPCPrivateSubnet3RouteTable192186F8: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC/PrivateSubnet3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet3/RouteTable 
  VPCPrivateSubnet3RouteTableAssociationC28D144E: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCPrivateSubnet3RouteTable192186F8 
      SubnetId: 
        Ref: VPCPrivateSubnet3Subnet3EDCD457 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet3/RouteTableAssociation 
  VPCPrivateSubnet3DefaultRoute27F311AE: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCPrivateSubnet3RouteTable192186F8 
      DestinationCidrBlock: 0.0.0.0/0 
      NatGatewayId: 
        Ref: VPCPublicSubnet3NATGatewayD3048F5C 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/PrivateSubnet3/DefaultRoute 
  VPCIGWB7E252D3: 
    Type: AWS::EC2::InternetGateway 
    Properties: 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSampleStack/VPC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/IGW 
  VPCVPCGW99B986DC: 
    Type: AWS::EC2::VPCGatewayAttachment 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      InternetGatewayId: 
        Ref: VPCIGWB7E252D3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSampleStack/VPC/VPCGW 
  CDKMetadata: 
    Type: AWS::CDK::Metadata 
    Properties: 
      Modules: aws-cdk=0.22.0,@aws-cdk/aws-ec2=0.22.0,@aws-cdk/cdk=0.22.0,@aws-cdk/cx-api=0.22.0,jsii-runtime=node.js/v10.2.1 
諸々といい感じに定義されています。IGWから直接インターネットと通信できるPublic Subnetと、NATGW経由でEgressの通信ができるPrivate Subnetが作成されることになります。デフォルトのVPCのCIDRは10.0.0.0/16、各サブネットは/19と大きく切られています。

  • スタックをデプロイします。
$ cdk deploy 
AwsCdkVpcSampleStack: deploying... 
AwsCdkVpcSampleStack: creating CloudFormation changeset... 
  0/35 | 17:12:26 | CREATE_IN_PROGRESS   | AWS::CloudFormation::Stack            | AwsCdkVpcSampleStack User Initiated 
  0/35 | 17:12:31 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/PublicSubnet2/EIP (VPCPublicSubnet2EIP4947BC00) 
  0/35 | 17:12:31 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/PublicSubnet3/EIP (VPCPublicSubnet3EIPAD4BC883) 
  0/35 | 17:12:31 | CREATE_IN_PROGRESS   | AWS::CDK::Metadata                    | CDKMetadata 
  0/35 | 17:12:32 | CREATE_IN_PROGRESS   | AWS::EC2::InternetGateway             | VPC/IGW (VPCIGWB7E252D3) 
  0/35 | 17:12:32 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/PublicSubnet1/EIP (VPCPublicSubnet1EIP6AD938E8) 
  0/35 | 17:12:32 | CREATE_IN_PROGRESS   | AWS::EC2::VPC                         | VPC (VPCB9E5F0B4) 
  0/35 | 17:12:32 | CREATE_IN_PROGRESS   | AWS::EC2::InternetGateway             | VPC/IGW (VPCIGWB7E252D3) Resource creation Initiated 
  0/35 | 17:12:32 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/PublicSubnet2/EIP (VPCPublicSubnet2EIP4947BC00) Resourcecreation Initiated 
  0/35 | 17:12:32 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/PublicSubnet1/EIP (VPCPublicSubnet1EIP6AD938E8) Resourcecreation Initiated 
  0/35 | 17:12:32 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/PublicSubnet3/EIP (VPCPublicSubnet3EIPAD4BC883) Resourcecreation Initiated 
  0/35 | 17:12:32 | CREATE_IN_PROGRESS   | AWS::EC2::VPC                         | VPC (VPCB9E5F0B4) Resource creation Initiated 
  0/35 | 17:12:35 | CREATE_IN_PROGRESS   | AWS::CDK::Metadata                    | CDKMetadata Resource creation Initiated 
  1/35 | 17:12:35 | CREATE_COMPLETE      | AWS::CDK::Metadata                    | CDKMetadata 
  2/35 | 17:12:48 | CREATE_COMPLETE      | AWS::EC2::EIP                         | VPC/PublicSubnet2/EIP (VPCPublicSubnet2EIP4947BC00) 
  3/35 | 17:12:48 | CREATE_COMPLETE      | AWS::EC2::EIP                         | VPC/PublicSubnet3/EIP (VPCPublicSubnet3EIPAD4BC883) 
  4/35 | 17:12:48 | CREATE_COMPLETE      | AWS::EC2::EIP                         | VPC/PublicSubnet1/EIP (VPCPublicSubnet1EIP6AD938E8) 
  5/35 | 17:12:49 | CREATE_COMPLETE      | AWS::EC2::InternetGateway             | VPC/IGW (VPCIGWB7E252D3) 
  6/35 | 17:12:50 | CREATE_COMPLETE      | AWS::EC2::VPC                         | VPC (VPCB9E5F0B4) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PrivateSubnet2/Subnet (VPCPrivateSubnet2SubnetCFCDAA7A) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PublicSubnet2/Subnet (VPCPublicSubnet2Subnet74179F39) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PublicSubnet2/RouteTable (VPCPublicSubnet2RouteTable6F1A15F1) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PrivateSubnet3/Subnet (VPCPrivateSubnet3Subnet3EDCD457) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PublicSubnet1/Subnet (VPCPublicSubnet1SubnetB4246D30) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PublicSubnet1/RouteTable (VPCPublicSubnet1RouteTableFEE4B781) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PrivateSubnet1/RouteTable (VPCPrivateSubnet1RouteTableBE8A6027) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PrivateSubnet3/RouteTable (VPCPrivateSubnet3RouteTable192186F8) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PrivateSubnet1/Subnet (VPCPrivateSubnet1Subnet8BCA10E0) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PrivateSubnet2/RouteTable (VPCPrivateSubnet2RouteTable0A19E10E) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PublicSubnet3/RouteTable (VPCPublicSubnet3RouteTable98AE0E14) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PublicSubnet2/RouteTable (VPCPublicSubnet2RouteTable6F1A15F1) Resource creation Initiated 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PublicSubnet3/Subnet (VPCPublicSubnet3Subnet631C5E25) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::VPCGatewayAttachment        | VPC/VPCGW (VPCVPCGW99B986DC) 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PrivateSubnet1/RouteTable (VPCPrivateSubnet1RouteTableBE8A6027) Resource creation Initiated 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PrivateSubnet3/RouteTable (VPCPrivateSubnet3RouteTable192186F8) Resource creation Initiated 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PrivateSubnet2/Subnet (VPCPrivateSubnet2SubnetCFCDAA7A) Resource creation Initiated 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PrivateSubnet3/Subnet (VPCPrivateSubnet3Subnet3EDCD457) Resource creation Initiated 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PrivateSubnet2/RouteTable (VPCPrivateSubnet2RouteTable0A19E10E) Resource creation Initiated 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PublicSubnet2/Subnet (VPCPublicSubnet2Subnet74179F39) Resource creation Initiated 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PrivateSubnet1/Subnet (VPCPrivateSubnet1Subnet8BCA10E0) Resource creation Initiated 
  6/35 | 17:12:53 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PublicSubnet3/RouteTable (VPCPublicSubnet3RouteTable98AE0E14) Resource creation Initiated 
  6/35 | 17:12:54 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/PublicSubnet1/RouteTable (VPCPublicSubnet1RouteTableFEE4B781) Resource creation Initiated 
  6/35 | 17:12:54 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PublicSubnet1/Subnet (VPCPublicSubnet1SubnetB4246D30) Resource creation Initiated 
  6/35 | 17:12:54 | CREATE_IN_PROGRESS   | AWS::EC2::VPCGatewayAttachment        | VPC/VPCGW (VPCVPCGW99B986DC) Resource creation Initiated 
  6/35 | 17:12:54 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/PublicSubnet3/Subnet (VPCPublicSubnet3Subnet631C5E25) Resource creation Initiated 
  7/35 | 17:12:54 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/PublicSubnet2/RouteTable (VPCPublicSubnet2RouteTable6F1A15F1) 
  8/35 | 17:12:54 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/PrivateSubnet3/RouteTable (VPCPrivateSubnet3RouteTable192186F8) 
  9/35 | 17:12:54 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/PrivateSubnet2/RouteTable (VPCPrivateSubnet2RouteTable0A19E10E) 
 10/35 | 17:12:54 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/PrivateSubnet1/RouteTable (VPCPrivateSubnet1RouteTableBE8A6027) 
 11/35 | 17:12:55 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/PublicSubnet1/RouteTable (VPCPublicSubnet1RouteTableFEE4B781) 
 12/35 | 17:12:55 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/PublicSubnet3/RouteTable (VPCPublicSubnet3RouteTable98AE0E14) 
 13/35 | 17:13:09 | CREATE_COMPLETE      | AWS::EC2::VPCGatewayAttachment        | VPC/VPCGW (VPCVPCGW99B986DC) 
 14/35 | 17:13:10 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/PublicSubnet2/Subnet (VPCPublicSubnet2Subnet74179F39) 
 15/35 | 17:13:10 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/PrivateSubnet1/Subnet (VPCPrivateSubnet1Subnet8BCA10E0) 
 16/35 | 17:13:10 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/PrivateSubnet2/Subnet (VPCPrivateSubnet2SubnetCFCDAA7A) 
 17/35 | 17:13:10 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/PrivateSubnet3/Subnet (VPCPrivateSubnet3Subnet3EDCD457) 
 18/35 | 17:13:10 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/PublicSubnet1/Subnet (VPCPublicSubnet1SubnetB4246D30) 
 19/35 | 17:13:10 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/PublicSubnet3/Subnet (VPCPublicSubnet3Subnet631C5E25) 
 19/35 | 17:13:12 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PublicSubnet2/DefaultRoute (VPCPublicSubnet2DefaultRouteB7481BBA) 
 19/35 | 17:13:12 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PublicSubnet3/DefaultRoute (VPCPublicSubnet3DefaultRouteA0D29D46) 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PublicSubnet1/DefaultRoute (VPCPublicSubnet1DefaultRoute91CEF279) 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet2/RouteTableAssociation (VPCPublicSubnet2RouteTableAssociation5A808732) 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/PublicSubnet2/NATGateway (VPCPublicSubnet2NATGateway3C070193) 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PublicSubnet2/DefaultRoute (VPCPublicSubnet2DefaultRouteB7481BBA) Resource creation Initiated 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet3/RouteTableAssociation (VPCPrivateSubnet3RouteTableAssociationC28D144E) 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/PublicSubnet1/NATGateway (VPCPublicSubnet1NATGatewayE0556630) 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PublicSubnet3/DefaultRoute (VPCPublicSubnet3DefaultRouteA0D29D46) Resource creation Initiated 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet1/RouteTableAssociation (VPCPublicSubnet1RouteTableAssociation0B0896DC) 
 19/35 | 17:13:13 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PublicSubnet1/DefaultRoute (VPCPublicSubnet1DefaultRoute91CEF279) Resource creation Initiated 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet2/RouteTableAssociation (VPCPrivateSubnet2RouteTableAssociation0C73D413) 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/PublicSubnet2/NATGateway (VPCPublicSubnet2NATGateway3C070193) Resource creation Initiated 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/PublicSubnet1/NATGateway (VPCPublicSubnet1NATGatewayE0556630) Resource creation Initiated 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/PublicSubnet3/NATGateway (VPCPublicSubnet3NATGatewayD3048F5C) 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet3/RouteTableAssociation (VPCPublicSubnet3RouteTableAssociation427FE0C6) 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet2/RouteTableAssociation (VPCPublicSubnet2RouteTableAssociation5A808732) Resource creation Initiated 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet1/RouteTableAssociation (VPCPrivateSubnet1RouteTableAssociation347902D1) 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet3/RouteTableAssociation (VPCPrivateSubnet3RouteTableAssociationC28D144E) Resource creation Initiated 
 19/35 | 17:13:14 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/PublicSubnet3/NATGateway (VPCPublicSubnet3NATGatewayD3048F5C) Resource creation Initiated 
 19/35 | 17:13:15 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet2/RouteTableAssociation (VPCPrivateSubnet2RouteTableAssociation0C73D413) Resource creation Initiated 
 19/35 | 17:13:15 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet1/RouteTableAssociation (VPCPublicSubnet1RouteTableAssociation0B0896DC) Resource creation Initiated 
 19/35 | 17:13:15 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet3/RouteTableAssociation (VPCPublicSubnet3RouteTableAssociation427FE0C6) Resource creation Initiated 
 19/35 | 17:13:15 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet1/RouteTableAssociation (VPCPrivateSubnet1RouteTableAssociation347902D1) Resource creation Initiated 
 20/35 | 17:13:29 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/PublicSubnet2/DefaultRoute (VPCPublicSubnet2DefaultRouteB7481BBA) 
 21/35 | 17:13:29 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/PublicSubnet3/DefaultRoute (VPCPublicSubnet3DefaultRouteA0D29D46) 
 22/35 | 17:13:29 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/PublicSubnet1/DefaultRoute (VPCPublicSubnet1DefaultRoute91CEF279) 
 23/35 | 17:13:30 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet2/RouteTableAssociation (VPCPublicSubnet2RouteTableAssociation5A808732) 
 24/35 | 17:13:30 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet3/RouteTableAssociation (VPCPrivateSubnet3RouteTableAssociationC28D144E) 
 25/35 | 17:13:30 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet2/RouteTableAssociation (VPCPrivateSubnet2RouteTableAssociation0C73D413) 
 26/35 | 17:13:30 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet1/RouteTableAssociation (VPCPublicSubnet1RouteTableAssociation0B0896DC) 
 27/35 | 17:13:31 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/PublicSubnet3/RouteTableAssociation (VPCPublicSubnet3RouteTableAssociation427FE0C6) 
 28/35 | 17:13:31 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/PrivateSubnet1/RouteTableAssociation (VPCPrivateSubnet1RouteTableAssociation347902D1) 
28/35 Currently in progress: AwsCdkVpcSampleStack, VPCPublicSubnet2NATGateway3C070193, VPCPublicSubnet1NATGatewayE0556630, VPCPublicSubnet3NATGatewayD3048F5C 
 29/35 | 17:14:47 | CREATE_COMPLETE      | AWS::EC2::NatGateway                  | VPC/PublicSubnet3/NATGateway (VPCPublicSubnet3NATGatewayD3048F5C) 
 30/35 | 17:14:47 | CREATE_COMPLETE      | AWS::EC2::NatGateway                  | VPC/PublicSubnet2/NATGateway (VPCPublicSubnet2NATGateway3C070193) 
 30/35 | 17:14:51 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PrivateSubnet3/DefaultRoute (VPCPrivateSubnet3DefaultRoute27F311AE) 
 30/35 | 17:14:51 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PrivateSubnet2/DefaultRoute (VPCPrivateSubnet2DefaultRouteF4F5CFD2) 
 30/35 | 17:14:52 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PrivateSubnet3/DefaultRoute (VPCPrivateSubnet3DefaultRoute27F311AE) Resource creation Initiated 
 30/35 | 17:14:52 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PrivateSubnet2/DefaultRoute (VPCPrivateSubnet2DefaultRouteF4F5CFD2) Resource creation Initiated 
 31/35 | 17:15:03 | CREATE_COMPLETE      | AWS::EC2::NatGateway                  | VPC/PublicSubnet1/NATGateway (VPCPublicSubnet1NATGatewayE0556630) 
 31/35 | 17:15:07 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PrivateSubnet1/DefaultRoute (VPCPrivateSubnet1DefaultRouteAE1D6490) 
 32/35 | 17:15:07 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/PrivateSubnet3/DefaultRoute (VPCPrivateSubnet3DefaultRoute27F311AE) 
 33/35 | 17:15:07 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/PrivateSubnet2/DefaultRoute (VPCPrivateSubnet2DefaultRouteF4F5CFD2) 
 33/35 | 17:15:07 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/PrivateSubnet1/DefaultRoute (VPCPrivateSubnet1DefaultRouteAE1D6490) Resource creation Initiated 
 34/35 | 17:15:23 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/PrivateSubnet1/DefaultRoute (VPCPrivateSubnet1DefaultRouteAE1D6490) 
 35/35 | 17:15:25 | CREATE_COMPLETE      | AWS::CloudFormation::Stack            | AwsCdkVpcSampleStack 
 
 ✅  AwsCdkVpcSampleStack 
 
Stack ARN: 
arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:stack/AwsCdkVpcSampleStack/c8b80820-1641-11e9-a0e4-0aa20f14f06e 
  • 作成されたCFnスタックを確認します。
$ aws cloudformation describe-stacks \ 
    --stack-name AwsCdkVpcSampleStack 
{ 
    "Stacks": [ 
        { 
            "StackId": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxx:stack/AwsCdkVpcSampleStack/c8b80820-1641-11e9-a0e4-0aa20f14f06e", 
            "StackName": "AwsCdkVpcSampleStack", 
            "ChangeSetId": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:changeSet/CDK-32b9a889-3f7e-429b-8058-1190aa6be4f1/aa63d1ae-6aef-4a80-a397-7d9a8ff23361", 
            "CreationTime": "2019-01-12T08:12:20.814Z", 
            "LastUpdatedTime": "2019-01-12T08:12:26.347Z", 
            "RollbackConfiguration": {}, 
            "StackStatus": "CREATE_COMPLETE", 
            "DisableRollback": false, 
            "NotificationARNs": [], 
            "Capabilities": [ 
                "CAPABILITY_IAM", 
                "CAPABILITY_NAMED_IAM" 
            ], 
            "Tags": [], 
            "EnableTerminationProtection": false, 
            "DriftInformation": { 
                "StackDriftStatus": "NOT_CHECKED" 
            } 
        } 
    ] 
} 
  • VPC IDを確認します。
$ aws cloudformation describe-stack-resources \ 
    --stack-name AwsCdkVpcSampleStack \ 
    --query StackResources[?ResourceType==\`AWS::EC2::VPC\`] 
[ 
    { 
        "StackName": "AwsCdkVpcSampleStack", 
        "StackId": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:stack/AwsCdkVpcSampleStack/c8b80820-1641-11e9-a0e4-0aa20f14f06e", 
        "LogicalResourceId": "VPCB9E5F0B4", 
        "PhysicalResourceId": "vpc-0bf2dd4b8911a4c06", 
        "ResourceType": "AWS::EC2::VPC", 
        "Timestamp": "2019-01-12T08:12:50.036Z", 
        "ResourceStatus": "CREATE_COMPLETE", 
        "DriftInformation": { 
            "StackResourceDriftStatus": "NOT_CHECKED" 
        } 
    } 
] 
  • VPCを確認します。
$ aws ec2 describe-vpcs --vpc-ids vpc-0bf2dd4b8911a4c06 
{ 
    "Vpcs": [ 
        { 
            "CidrBlock": "10.0.0.0/16", 
            "DhcpOptionsId": "dopt-a74006c0", 
            "State": "available", 
            "VpcId": "vpc-0bf2dd4b8911a4c06", 
            "OwnerId": "xxxxxxxxxxxx", 
            "InstanceTenancy": "default", 
            "CidrBlockAssociationSet": [ 
                { 
                    "AssociationId": "vpc-cidr-assoc-06e23c526e705716e", 
                    "CidrBlock": "10.0.0.0/16", 
                    "CidrBlockState": { 
                        "State": "associated" 
                    } 
                } 
            ], 
            "IsDefault": false, 
            "Tags": [ 
                { 
                    "Key": "aws:cloudformation:stack-name", 
                    "Value": "AwsCdkVpcSampleStack" 
                }, 
                { 
                    "Key": "Name", 
                    "Value": "AwsCdkVpcSampleStack/VPC" 
                }, 
                { 
                    "Key": "aws:cloudformation:stack-id", 
                    "Value": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:stack/AwsCdkVpcSampleStack/c8b80820-1641-11e9-a0e4-0aa20f14f06e" 
                }, 
                { 
                    "Key": "aws:cloudformation:logical-id", 
                    "Value": "VPCB9E5F0B4" 
                } 
            ] 
        } 
    ] 
} 


VPC CIDR、Subnet Type、 Subnet CIDRを指定してVPCを作成する。

今度はVPCのCIDR、Subnet Type、 SubnetのCIDRを指定してVPCを作成します。新規にaws-cdk-vpc-sample2ディレクトリを作ってプロジェクトの初期化とec2モジュールのインストールを実施しておきます。


  • lib/aws-cdk-vpc-sample.tsを編集します。
import cdk = require('@aws-cdk/cdk'); 
import ec2 = require('@aws-cdk/aws-ec2'); 
 
export class AwsCdkVpcSample2Stack extends cdk.Stack { 
  constructor(scope: cdk.App, id: string, props?: cdk.StackProps) { 
    super(scope, id, props); 
 
    new ec2.VpcNetwork(this, 'VPC', { 
      cidr: '10.0.0.0/16', 
      subnetConfiguration: [ 
        { 
          cidrMask: 24, 
          name: 'Ingress', 
          subnetType: ec2.SubnetType.Public, 
        }, 
        { 
          cidrMask: 24, 
          name: 'Application', 
          subnetType: ec2.SubnetType.Private, 
        }, 
        { 
          cidrMask: 28, 
          name: 'Database', 
          subnetType: ec2.SubnetType.Isolated, 
        } 
      ], 
    }); 
  } 
} 
雛形として用意されているSubnet Typeには以下があり、ルートテーブルが適切に設定されます。

サブネット種類 通信ポリシー
Public インターネットと両方向に通信可能
Private インターネットへはNATGWを通してアウトバウンドのみ通信可能
Isolated インターネットへは通信不可

  • bin/aws-cdk-vpc-sample2.tsを編集し、リージョンをStack作成時のプロパティとして指定してみます。
#!/usr/bin/env node 
import cdk = require('@aws-cdk/cdk'); 
import { AwsCdkVpcSample2Stack } from '../lib/aws-cdk-vpc-sample2-stack'; 
 
const app = new cdk.App(); 
new AwsCdkVpcSample2Stack(app, 'AwsCdkVpcSample2Stack', { env: { region: 'ap-northeast-1' } });    //展開するリージョンを指定する。ここに展開するアカウントも指定可能。 
app.run(); 
  • ビルドします。
$ npm run build 

  • cdk diffコマンドを実行すると作成されるリソースが表示されます。
    AWSクレデンシャルが設定されていないとエラーになります。
$ cdk diff 
Resources 
[+] AWS::EC2::VPC VPC VPCB9E5F0B4 
[+] AWS::EC2::Subnet VPC/IngressSubnet1/Subnet VPCIngressSubnet1Subnet4257CD65 
[+] AWS::EC2::RouteTable VPC/IngressSubnet1/RouteTable VPCIngressSubnet1RouteTable9BE753A6 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/IngressSubnet1/RouteTableAssociation VPCIngressSubnet1RouteTableAssociationCAFE4089 
[+] AWS::EC2::Route VPC/IngressSubnet1/DefaultRoute VPCIngressSubnet1DefaultRouteFE025494 
[+] AWS::EC2::EIP VPC/IngressSubnet1/EIP VPCIngressSubnet1EIP99406D22 
[+] AWS::EC2::NatGateway VPC/IngressSubnet1/NATGateway VPCIngressSubnet1NATGatewayEA4AE80E 
[+] AWS::EC2::Subnet VPC/IngressSubnet2/Subnet VPCIngressSubnet2SubnetE0EA735B 
[+] AWS::EC2::RouteTable VPC/IngressSubnet2/RouteTable VPCIngressSubnet2RouteTableDFE1B4BC 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/IngressSubnet2/RouteTableAssociation VPCIngressSubnet2RouteTableAssociationB244DE25 
[+] AWS::EC2::Route VPC/IngressSubnet2/DefaultRoute VPCIngressSubnet2DefaultRoute9FF8300E 
[+] AWS::EC2::EIP VPC/IngressSubnet2/EIP VPCIngressSubnet2EIPCE44C233 
[+] AWS::EC2::NatGateway VPC/IngressSubnet2/NATGateway VPCIngressSubnet2NATGateway68BB4190 
[+] AWS::EC2::Subnet VPC/IngressSubnet3/Subnet VPCIngressSubnet3Subnet5B03B6AE 
[+] AWS::EC2::RouteTable VPC/IngressSubnet3/RouteTable VPCIngressSubnet3RouteTableBA29E68D 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/IngressSubnet3/RouteTableAssociation VPCIngressSubnet3RouteTableAssociationF8544212 
[+] AWS::EC2::Route VPC/IngressSubnet3/DefaultRoute VPCIngressSubnet3DefaultRouteD4DCD60F 
[+] AWS::EC2::EIP VPC/IngressSubnet3/EIP VPCIngressSubnet3EIP7A19F11D 
[+] AWS::EC2::NatGateway VPC/IngressSubnet3/NATGateway VPCIngressSubnet3NATGatewayF804BFD1 
[+] AWS::EC2::Subnet VPC/ApplicationSubnet1/Subnet VPCApplicationSubnet1SubnetCE118F80 
[+] AWS::EC2::RouteTable VPC/ApplicationSubnet1/RouteTable VPCApplicationSubnet1RouteTable5B6CE71A 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/ApplicationSubnet1/RouteTableAssociation VPCApplicationSubnet1RouteTableAssociation8DF0EAE5 
[+] AWS::EC2::Route VPC/ApplicationSubnet1/DefaultRoute VPCApplicationSubnet1DefaultRouteA4E47D36 
[+] AWS::EC2::Subnet VPC/ApplicationSubnet2/Subnet VPCApplicationSubnet2Subnet988E96B1 
[+] AWS::EC2::RouteTable VPC/ApplicationSubnet2/RouteTable VPCApplicationSubnet2RouteTableFDC3EEE6 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/ApplicationSubnet2/RouteTableAssociation VPCApplicationSubnet2RouteTableAssociationD84040F3 
[+] AWS::EC2::Route VPC/ApplicationSubnet2/DefaultRoute VPCApplicationSubnet2DefaultRouteC3680A52 
[+] AWS::EC2::Subnet VPC/ApplicationSubnet3/Subnet VPCApplicationSubnet3Subnet152008D5 
[+] AWS::EC2::RouteTable VPC/ApplicationSubnet3/RouteTable VPCApplicationSubnet3RouteTable29639657 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/ApplicationSubnet3/RouteTableAssociation VPCApplicationSubnet3RouteTableAssociationB4462F03 
[+] AWS::EC2::Route VPC/ApplicationSubnet3/DefaultRoute VPCApplicationSubnet3DefaultRoute33D8EB24 
[+] AWS::EC2::Subnet VPC/DatabaseSubnet1/Subnet VPCDatabaseSubnet1Subnet3E790B6F 
[+] AWS::EC2::RouteTable VPC/DatabaseSubnet1/RouteTable VPCDatabaseSubnet1RouteTable50155611 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/DatabaseSubnet1/RouteTableAssociation VPCDatabaseSubnet1RouteTableAssociation56EE26FE 
[+] AWS::EC2::Subnet VPC/DatabaseSubnet2/Subnet VPCDatabaseSubnet2Subnet93B13DD5 
[+] AWS::EC2::RouteTable VPC/DatabaseSubnet2/RouteTable VPCDatabaseSubnet2RouteTable5A3ECF56 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/DatabaseSubnet2/RouteTableAssociation VPCDatabaseSubnet2RouteTableAssociation2350B25C 
[+] AWS::EC2::Subnet VPC/DatabaseSubnet3/Subnet VPCDatabaseSubnet3SubnetBC9F7BFD 
[+] AWS::EC2::RouteTable VPC/DatabaseSubnet3/RouteTable VPCDatabaseSubnet3RouteTableF4BFD0C7 
[+] AWS::EC2::SubnetRouteTableAssociation VPC/DatabaseSubnet3/RouteTableAssociation VPCDatabaseSubnet3RouteTableAssociationC74EC212 
[+] AWS::EC2::InternetGateway VPC/IGW VPCIGWB7E252D3 
[+] AWS::EC2::VPCGatewayAttachment VPC/VPCGW VPCVPCGW99B986DC 
  • CDKによって作成されるCloudFormationスタックのテンプレート(Resources)を確認します。
$ cdk synth AwsCdkVpcSample2Stack 
Resources: 
  VPCB9E5F0B4: 
    Type: AWS::EC2::VPC 
    Properties: 
      CidrBlock: 10.0.0.0/16 
      EnableDnsHostnames: true 
      EnableDnsSupport: true 
      InstanceTenancy: default 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/Resource 
  VPCIngressSubnet1Subnet4257CD65: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.0.0/24 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1a 
      MapPublicIpOnLaunch: true 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet1 
        - Key: aws-cdk:subnet-name 
          Value: Ingress 
        - Key: aws-cdk:subnet-type 
          Value: Public 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet1/Subnet 
  VPCIngressSubnet1RouteTable9BE753A6: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet1/RouteTable 
  VPCIngressSubnet1RouteTableAssociationCAFE4089: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCIngressSubnet1RouteTable9BE753A6 
      SubnetId: 
        Ref: VPCIngressSubnet1Subnet4257CD65 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet1/RouteTableAssociation 
  VPCIngressSubnet1DefaultRouteFE025494: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCIngressSubnet1RouteTable9BE753A6 
      DestinationCidrBlock: 0.0.0.0/0 
      GatewayId: 
        Ref: VPCIGWB7E252D3 
    DependsOn: 
      - VPCVPCGW99B986DC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet1/DefaultRoute 
  VPCIngressSubnet1EIP99406D22: 
    Type: AWS::EC2::EIP 
    Properties: 
      Domain: vpc 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet1/EIP 
  VPCIngressSubnet1NATGatewayEA4AE80E: 
    Type: AWS::EC2::NatGateway 
    Properties: 
      AllocationId: 
        Fn::GetAtt: 
          - VPCIngressSubnet1EIP99406D22 
          - AllocationId 
      SubnetId: 
        Ref: VPCIngressSubnet1Subnet4257CD65 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet1/NATGateway 
  VPCIngressSubnet2SubnetE0EA735B: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.1.0/24 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1c 
      MapPublicIpOnLaunch: true 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet2 
        - Key: aws-cdk:subnet-name 
          Value: Ingress 
        - Key: aws-cdk:subnet-type 
          Value: Public 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet2/Subnet 
  VPCIngressSubnet2RouteTableDFE1B4BC: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet2 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet2/RouteTable 
  VPCIngressSubnet2RouteTableAssociationB244DE25: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCIngressSubnet2RouteTableDFE1B4BC 
      SubnetId: 
        Ref: VPCIngressSubnet2SubnetE0EA735B 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet2/RouteTableAssociation 
  VPCIngressSubnet2DefaultRoute9FF8300E: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCIngressSubnet2RouteTableDFE1B4BC 
      DestinationCidrBlock: 0.0.0.0/0 
      GatewayId: 
        Ref: VPCIGWB7E252D3 
    DependsOn: 
      - VPCVPCGW99B986DC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet2/DefaultRoute 
  VPCIngressSubnet2EIPCE44C233: 
    Type: AWS::EC2::EIP 
    Properties: 
      Domain: vpc 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet2/EIP 
  VPCIngressSubnet2NATGateway68BB4190: 
    Type: AWS::EC2::NatGateway 
    Properties: 
      AllocationId: 
        Fn::GetAtt: 
          - VPCIngressSubnet2EIPCE44C233 
          - AllocationId 
      SubnetId: 
        Ref: VPCIngressSubnet2SubnetE0EA735B 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet2 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet2/NATGateway 
  VPCIngressSubnet3Subnet5B03B6AE: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.2.0/24 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1d 
      MapPublicIpOnLaunch: true 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet3 
        - Key: aws-cdk:subnet-name 
          Value: Ingress 
        - Key: aws-cdk:subnet-type 
          Value: Public 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet3/Subnet 
  VPCIngressSubnet3RouteTableBA29E68D: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet3/RouteTable 
  VPCIngressSubnet3RouteTableAssociationF8544212: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCIngressSubnet3RouteTableBA29E68D 
      SubnetId: 
        Ref: VPCIngressSubnet3Subnet5B03B6AE 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet3/RouteTableAssociation 
  VPCIngressSubnet3DefaultRouteD4DCD60F: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCIngressSubnet3RouteTableBA29E68D 
      DestinationCidrBlock: 0.0.0.0/0 
      GatewayId: 
        Ref: VPCIGWB7E252D3 
    DependsOn: 
      - VPCVPCGW99B986DC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet3/DefaultRoute 
  VPCIngressSubnet3EIP7A19F11D: 
    Type: AWS::EC2::EIP 
    Properties: 
      Domain: vpc 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet3/EIP 
  VPCIngressSubnet3NATGatewayF804BFD1: 
    Type: AWS::EC2::NatGateway 
    Properties: 
      AllocationId: 
        Fn::GetAtt: 
          - VPCIngressSubnet3EIP7A19F11D 
          - AllocationId 
      SubnetId: 
        Ref: VPCIngressSubnet3Subnet5B03B6AE 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/IngressSubnet3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IngressSubnet3/NATGateway 
  VPCApplicationSubnet1SubnetCE118F80: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.3.0/24 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1a 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet1 
        - Key: aws-cdk:subnet-name 
          Value: Application 
        - Key: aws-cdk:subnet-type 
          Value: Private 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet1/Subnet 
  VPCApplicationSubnet1RouteTable5B6CE71A: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet1/RouteTable 
  VPCApplicationSubnet1RouteTableAssociation8DF0EAE5: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCApplicationSubnet1RouteTable5B6CE71A 
      SubnetId: 
        Ref: VPCApplicationSubnet1SubnetCE118F80 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet1/RouteTableAssociation 
  VPCApplicationSubnet1DefaultRouteA4E47D36: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCApplicationSubnet1RouteTable5B6CE71A 
      DestinationCidrBlock: 0.0.0.0/0 
      NatGatewayId: 
        Ref: VPCIngressSubnet1NATGatewayEA4AE80E 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet1/DefaultRoute 
  VPCApplicationSubnet2Subnet988E96B1: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.4.0/24 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1c 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet2 
        - Key: aws-cdk:subnet-name 
          Value: Application 
        - Key: aws-cdk:subnet-type 
          Value: Private 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet2/Subnet 
  VPCApplicationSubnet2RouteTableFDC3EEE6: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet2 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet2/RouteTable 
  VPCApplicationSubnet2RouteTableAssociationD84040F3: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCApplicationSubnet2RouteTableFDC3EEE6 
      SubnetId: 
        Ref: VPCApplicationSubnet2Subnet988E96B1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet2/RouteTableAssociation 
  VPCApplicationSubnet2DefaultRouteC3680A52: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCApplicationSubnet2RouteTableFDC3EEE6 
      DestinationCidrBlock: 0.0.0.0/0 
      NatGatewayId: 
        Ref: VPCIngressSubnet2NATGateway68BB4190 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet2/DefaultRoute 
  VPCApplicationSubnet3Subnet152008D5: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.5.0/24 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1d 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet3 
        - Key: aws-cdk:subnet-name 
          Value: Application 
        - Key: aws-cdk:subnet-type 
          Value: Private 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet3/Subnet 
  VPCApplicationSubnet3RouteTable29639657: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet3/RouteTable 
  VPCApplicationSubnet3RouteTableAssociationB4462F03: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCApplicationSubnet3RouteTable29639657 
      SubnetId: 
        Ref: VPCApplicationSubnet3Subnet152008D5 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet3/RouteTableAssociation 
  VPCApplicationSubnet3DefaultRoute33D8EB24: 
    Type: AWS::EC2::Route 
    Properties: 
      RouteTableId: 
        Ref: VPCApplicationSubnet3RouteTable29639657 
      DestinationCidrBlock: 0.0.0.0/0 
      NatGatewayId: 
        Ref: VPCIngressSubnet3NATGatewayF804BFD1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/ApplicationSubnet3/DefaultRoute 
  VPCDatabaseSubnet1Subnet3E790B6F: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.6.0/28 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1a 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet1 
        - Key: aws-cdk:subnet-type 
          Value: Isolated 
        - Key: aws-cdk:subnet-name 
          Value: Database 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet1/Subnet 
  VPCDatabaseSubnet1RouteTable50155611: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet1 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet1/RouteTable 
  VPCDatabaseSubnet1RouteTableAssociation56EE26FE: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCDatabaseSubnet1RouteTable50155611 
      SubnetId: 
        Ref: VPCDatabaseSubnet1Subnet3E790B6F 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet1/RouteTableAssociation 
  VPCDatabaseSubnet2Subnet93B13DD5: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.6.16/28 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1c 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet2 
        - Key: aws-cdk:subnet-type 
          Value: Isolated 
        - Key: aws-cdk:subnet-name 
          Value: Database 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet2/Subnet 
  VPCDatabaseSubnet2RouteTable5A3ECF56: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet2 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet2/RouteTable 
  VPCDatabaseSubnet2RouteTableAssociation2350B25C: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCDatabaseSubnet2RouteTable5A3ECF56 
      SubnetId: 
        Ref: VPCDatabaseSubnet2Subnet93B13DD5 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet2/RouteTableAssociation 
  VPCDatabaseSubnet3SubnetBC9F7BFD: 
    Type: AWS::EC2::Subnet 
    Properties: 
      CidrBlock: 10.0.6.32/28 
      VpcId: 
        Ref: VPCB9E5F0B4 
      AvailabilityZone: ap-northeast-1d 
      MapPublicIpOnLaunch: false 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet3 
        - Key: aws-cdk:subnet-type 
          Value: Isolated 
        - Key: aws-cdk:subnet-name 
          Value: Database 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet3/Subnet 
  VPCDatabaseSubnet3RouteTableF4BFD0C7: 
    Type: AWS::EC2::RouteTable 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet3/RouteTable 
  VPCDatabaseSubnet3RouteTableAssociationC74EC212: 
    Type: AWS::EC2::SubnetRouteTableAssociation 
    Properties: 
      RouteTableId: 
        Ref: VPCDatabaseSubnet3RouteTableF4BFD0C7 
      SubnetId: 
        Ref: VPCDatabaseSubnet3SubnetBC9F7BFD 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/DatabaseSubnet3/RouteTableAssociation 
  VPCIGWB7E252D3: 
    Type: AWS::EC2::InternetGateway 
    Properties: 
      Tags: 
        - Key: Name 
          Value: AwsCdkVpcSample2Stack/VPC 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/IGW 
  VPCVPCGW99B986DC: 
    Type: AWS::EC2::VPCGatewayAttachment 
    Properties: 
      VpcId: 
        Ref: VPCB9E5F0B4 
      InternetGatewayId: 
        Ref: VPCIGWB7E252D3 
    Metadata: 
      aws:cdk:path: AwsCdkVpcSample2Stack/VPC/VPCGW 
  CDKMetadata: 
    Type: AWS::CDK::Metadata 
    Properties: 
      Modules: aws-cdk=0.22.0,@aws-cdk/aws-ec2=0.22.0,@aws-cdk/cdk=0.22.0,@aws-cdk/cx-api=0.22.0,jsii-runtime=node.js/v10.2.1 
  • スタックをデプロイします。
$ cdk deploy 
AwsCdkVpcSample2Stack: deploying... 
AwsCdkVpcSample2Stack: creating CloudFormation changeset... 
  0/44 | 18:23:21 | CREATE_IN_PROGRESS   | AWS::CloudFormation::Stack            | AwsCdkVpcSample2Stack User Initiated 
  0/44 | 18:23:26 | CREATE_IN_PROGRESS   | AWS::CDK::Metadata                    | CDKMetadata 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/IngressSubnet3/EIP (VPCIngressSubnet3EIP7A19F11D) 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/IngressSubnet2/EIP (VPCIngressSubnet2EIPCE44C233) 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::InternetGateway             | VPC/IGW (VPCIGWB7E252D3) 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::VPC                         | VPC (VPCB9E5F0B4) 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/IngressSubnet1/EIP (VPCIngressSubnet1EIP99406D22) 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/IngressSubnet3/EIP (VPCIngressSubnet3EIP7A19F11D) Resource creation Initiated 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::InternetGateway             | VPC/IGW (VPCIGWB7E252D3) Resource creation Initiated 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/IngressSubnet2/EIP (VPCIngressSubnet2EIPCE44C233) Resource creation Initiated 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::EIP                         | VPC/IngressSubnet1/EIP (VPCIngressSubnet1EIP99406D22) Resource creation Initiated 
  0/44 | 18:23:27 | CREATE_IN_PROGRESS   | AWS::EC2::VPC                         | VPC (VPCB9E5F0B4) Resource creation Initiated 
  0/44 | 18:23:29 | CREATE_IN_PROGRESS   | AWS::CDK::Metadata                    | CDKMetadata Resource creation Initiated 
  1/44 | 18:23:29 | CREATE_COMPLETE      | AWS::CDK::Metadata                    | CDKMetadata 
  2/44 | 18:23:43 | CREATE_COMPLETE      | AWS::EC2::EIP                         | VPC/IngressSubnet3/EIP (VPCIngressSubnet3EIP7A19F11D) 
  3/44 | 18:23:43 | CREATE_COMPLETE      | AWS::EC2::EIP                         | VPC/IngressSubnet1/EIP (VPCIngressSubnet1EIP99406D22) 
  4/44 | 18:23:43 | CREATE_COMPLETE      | AWS::EC2::EIP                         | VPC/IngressSubnet2/EIP (VPCIngressSubnet2EIPCE44C233) 
  5/44 | 18:23:43 | CREATE_COMPLETE      | AWS::EC2::InternetGateway             | VPC/IGW (VPCIGWB7E252D3) 
  6/44 | 18:23:44 | CREATE_COMPLETE      | AWS::EC2::VPC                         | VPC (VPCB9E5F0B4) 
  6/44 | 18:23:47 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/ApplicationSubnet1/Subnet (VPCApplicationSubnet1SubnetCE118F80) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/DatabaseSubnet2/Subnet (VPCDatabaseSubnet2Subnet93B13DD5) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/IngressSubnet1/RouteTable (VPCIngressSubnet1RouteTable9BE753A6) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/IngressSubnet3/RouteTable (VPCIngressSubnet3RouteTableBA29E68D) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/ApplicationSubnet3/Subnet (VPCApplicationSubnet3Subnet152008D5) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/DatabaseSubnet1/Subnet (VPCDatabaseSubnet1Subnet3E790B6F) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet1/RouteTable (VPCApplicationSubnet1RouteTable5B6CE71A) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/IngressSubnet1/Subnet (VPCIngressSubnet1Subnet4257CD65) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/IngressSubnet3/Subnet (VPCIngressSubnet3Subnet5B03B6AE) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/ApplicationSubnet2/Subnet (VPCApplicationSubnet2Subnet988E96B1) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet2/RouteTable (VPCApplicationSubnet2RouteTableFDC3EEE6) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet2/RouteTable (VPCDatabaseSubnet2RouteTable5A3ECF56) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::VPCGatewayAttachment        | VPC/VPCGW (VPCVPCGW99B986DC) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/DatabaseSubnet3/Subnet (VPCDatabaseSubnet3SubnetBC9F7BFD) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/IngressSubnet2/RouteTable (VPCIngressSubnet2RouteTableDFE1B4BC) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet3/RouteTable (VPCApplicationSubnet3RouteTable29639657) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet1/RouteTable (VPCDatabaseSubnet1RouteTable50155611) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/IngressSubnet2/Subnet (VPCIngressSubnet2SubnetE0EA735B) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/IngressSubnet1/RouteTable (VPCIngressSubnet1RouteTable9BE753A6) Resource creation Initiated 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/ApplicationSubnet1/Subnet (VPCApplicationSubnet1SubnetCE118F80) Resource creation Initiated 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/IngressSubnet3/RouteTable (VPCIngressSubnet3RouteTableBA29E68D) Resource creation Initiated 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/DatabaseSubnet2/Subnet (VPCDatabaseSubnet2Subnet93B13DD5) Resource creation Initiated 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet3/RouteTable (VPCDatabaseSubnet3RouteTableF4BFD0C7) 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet1/RouteTable (VPCApplicationSubnet1RouteTable5B6CE71A) Resource creation Initiated 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/DatabaseSubnet1/Subnet (VPCDatabaseSubnet1Subnet3E790B6F) Resource creation Initiated 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet2/RouteTable (VPCDatabaseSubnet2RouteTable5A3ECF56) Resource creation Initiated 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/ApplicationSubnet3/Subnet (VPCApplicationSubnet3Subnet152008D5) Resource creation Initiated 
  6/44 | 18:23:48 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/IngressSubnet1/Subnet (VPCIngressSubnet1Subnet4257CD65) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/IngressSubnet2/RouteTable (VPCIngressSubnet2RouteTableDFE1B4BC) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/IngressSubnet3/Subnet (VPCIngressSubnet3Subnet5B03B6AE) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet1/RouteTable (VPCDatabaseSubnet1RouteTable50155611) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/DatabaseSubnet3/Subnet (VPCDatabaseSubnet3SubnetBC9F7BFD) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet2/RouteTable (VPCApplicationSubnet2RouteTableFDC3EEE6) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet3/RouteTable (VPCApplicationSubnet3RouteTable29639657) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/IngressSubnet2/Subnet (VPCIngressSubnet2SubnetE0EA735B) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet3/RouteTable (VPCDatabaseSubnet3RouteTableF4BFD0C7) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::VPCGatewayAttachment        | VPC/VPCGW (VPCVPCGW99B986DC) Resource creation Initiated 
  6/44 | 18:23:49 | CREATE_IN_PROGRESS   | AWS::EC2::Subnet                      | VPC/ApplicationSubnet2/Subnet (VPCApplicationSubnet2Subnet988E96B1) Resource creation Initiated 
  7/44 | 18:23:49 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/IngressSubnet1/RouteTable (VPCIngressSubnet1RouteTable9BE753A6) 
  8/44 | 18:23:49 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet1/RouteTable (VPCApplicationSubnet1RouteTable5B6CE71A) 
  9/44 | 18:23:49 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/IngressSubnet3/RouteTable (VPCIngressSubnet3RouteTableBA29E68D) 
 10/44 | 18:23:50 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet2/RouteTable (VPCDatabaseSubnet2RouteTable5A3ECF56) 
 11/44 | 18:23:50 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet2/RouteTable (VPCApplicationSubnet2RouteTableFDC3EEE6) 
 12/44 | 18:23:50 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet1/RouteTable (VPCDatabaseSubnet1RouteTable50155611) 
 13/44 | 18:23:50 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/ApplicationSubnet3/RouteTable (VPCApplicationSubnet3RouteTable29639657) 
 14/44 | 18:23:50 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/IngressSubnet2/RouteTable (VPCIngressSubnet2RouteTableDFE1B4BC) 
 15/44 | 18:23:50 | CREATE_COMPLETE      | AWS::EC2::RouteTable                  | VPC/DatabaseSubnet3/RouteTable (VPCDatabaseSubnet3RouteTableF4BFD0C7) 
 16/44 | 18:24:04 | CREATE_COMPLETE      | AWS::EC2::VPCGatewayAttachment        | VPC/VPCGW (VPCVPCGW99B986DC) 
 17/44 | 18:24:04 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/DatabaseSubnet2/Subnet (VPCDatabaseSubnet2Subnet93B13DD5) 
 18/44 | 18:24:05 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/DatabaseSubnet1/Subnet (VPCDatabaseSubnet1Subnet3E790B6F) 
 19/44 | 18:24:05 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/ApplicationSubnet1/Subnet (VPCApplicationSubnet1SubnetCE118F80) 
 20/44 | 18:24:05 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/ApplicationSubnet3/Subnet (VPCApplicationSubnet3Subnet152008D5) 
 21/44 | 18:24:05 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/IngressSubnet1/Subnet (VPCIngressSubnet1Subnet4257CD65) 
 22/44 | 18:24:05 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/DatabaseSubnet3/Subnet (VPCDatabaseSubnet3SubnetBC9F7BFD) 
 23/44 | 18:24:05 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/IngressSubnet3/Subnet (VPCIngressSubnet3Subnet5B03B6AE) 
 24/44 | 18:24:05 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/ApplicationSubnet2/Subnet (VPCApplicationSubnet2Subnet988E96B1) 
 25/44 | 18:24:05 | CREATE_COMPLETE      | AWS::EC2::Subnet                      | VPC/IngressSubnet2/Subnet (VPCIngressSubnet2SubnetE0EA735B) 
 25/44 | 18:24:07 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/IngressSubnet3/DefaultRoute (VPCIngressSubnet3DefaultRouteD4DCD60F) 
 25/44 | 18:24:07 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/IngressSubnet1/DefaultRoute (VPCIngressSubnet1DefaultRouteFE025494) 
 25/44 | 18:24:07 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet3/RouteTableAssociation (VPCApplicationSubnet3RouteTableAssociationB4462F03) 
 25/44 | 18:24:07 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/IngressSubnet2/DefaultRoute (VPCIngressSubnet2DefaultRoute9FF8300E) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/IngressSubnet3/DefaultRoute (VPCIngressSubnet3DefaultRouteD4DCD60F) Resource creation Initiated 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet1/RouteTableAssociation (VPCIngressSubnet1RouteTableAssociationCAFE4089) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet1/RouteTableAssociation (VPCApplicationSubnet1RouteTableAssociation8DF0EAE5) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet1/RouteTableAssociation (VPCDatabaseSubnet1RouteTableAssociation56EE26FE) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet3/RouteTableAssociation (VPCIngressSubnet3RouteTableAssociationF8544212) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet2/RouteTableAssociation (VPCDatabaseSubnet2RouteTableAssociation2350B25C) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/IngressSubnet1/DefaultRoute (VPCIngressSubnet1DefaultRouteFE025494) Resource creation Initiated 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet3/RouteTableAssociation (VPCDatabaseSubnet3RouteTableAssociationC74EC212) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/IngressSubnet2/DefaultRoute (VPCIngressSubnet2DefaultRoute9FF8300E) Resource creation Initiated 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/IngressSubnet1/NATGateway (VPCIngressSubnet1NATGatewayEA4AE80E) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet2/RouteTableAssociation (VPCApplicationSubnet2RouteTableAssociationD84040F3) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet2/RouteTableAssociation (VPCIngressSubnet2RouteTableAssociationB244DE25) 
 25/44 | 18:24:08 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/IngressSubnet3/NATGateway (VPCIngressSubnet3NATGatewayF804BFD1) 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/IngressSubnet2/NATGateway (VPCIngressSubnet2NATGateway68BB4190) 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet3/RouteTableAssociation (VPCApplicationSubnet3RouteTableAssociationB4462F03) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/IngressSubnet1/NATGateway (VPCIngressSubnet1NATGatewayEA4AE80E) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/IngressSubnet3/NATGateway (VPCIngressSubnet3NATGatewayF804BFD1) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet1/RouteTableAssociation (VPCApplicationSubnet1RouteTableAssociation8DF0EAE5) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet3/RouteTableAssociation (VPCIngressSubnet3RouteTableAssociationF8544212) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet1/RouteTableAssociation (VPCIngressSubnet1RouteTableAssociationCAFE4089) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet1/RouteTableAssociation (VPCDatabaseSubnet1RouteTableAssociation56EE26FE) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet2/RouteTableAssociation (VPCDatabaseSubnet2RouteTableAssociation2350B25C) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::NatGateway                  | VPC/IngressSubnet2/NATGateway (VPCIngressSubnet2NATGateway68BB4190) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet3/RouteTableAssociation (VPCDatabaseSubnet3RouteTableAssociationC74EC212) Resource creation Initiated 
 25/44 | 18:24:09 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet2/RouteTableAssociation (VPCApplicationSubnet2RouteTableAssociationD84040F3) Resource creation Initiated 
 25/44 | 18:24:10 | CREATE_IN_PROGRESS   | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet2/RouteTableAssociation (VPCIngressSubnet2RouteTableAssociationB244DE25) Resource creation Initiated 
 26/44 | 18:24:23 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/IngressSubnet3/DefaultRoute (VPCIngressSubnet3DefaultRouteD4DCD60F) 
 27/44 | 18:24:24 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/IngressSubnet1/DefaultRoute (VPCIngressSubnet1DefaultRouteFE025494) 
 28/44 | 18:24:24 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/IngressSubnet2/DefaultRoute (VPCIngressSubnet2DefaultRoute9FF8300E) 
 29/44 | 18:24:24 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet3/RouteTableAssociation (VPCApplicationSubnet3RouteTableAssociationB4462F03) 
 30/44 | 18:24:24 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet1/RouteTableAssociation (VPCApplicationSubnet1RouteTableAssociation8DF0EAE5) 
 31/44 | 18:24:25 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet1/RouteTableAssociation (VPCIngressSubnet1RouteTableAssociationCAFE4089) 
 32/44 | 18:24:25 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet1/RouteTableAssociation (VPCDatabaseSubnet1RouteTableAssociation56EE26FE) 
 33/44 | 18:24:25 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet2/RouteTableAssociation (VPCDatabaseSubnet2RouteTableAssociation2350B25C) 
 34/44 | 18:24:25 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet3/RouteTableAssociation (VPCIngressSubnet3RouteTableAssociationF8544212) 
 35/44 | 18:24:25 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/DatabaseSubnet3/RouteTableAssociation (VPCDatabaseSubnet3RouteTableAssociationC74EC212) 
 36/44 | 18:24:25 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/IngressSubnet2/RouteTableAssociation (VPCIngressSubnet2RouteTableAssociationB244DE25) 
 37/44 | 18:24:25 | CREATE_COMPLETE      | AWS::EC2::SubnetRouteTableAssociation | VPC/ApplicationSubnet2/RouteTableAssociation (VPCApplicationSubnet2RouteTableAssociationD84040F3) 
37/44 Currently in progress: AwsCdkVpcSample2Stack, VPCIngressSubnet1NATGatewayEA4AE80E, VPCIngressSubnet3NATGatewayF804BFD1, VPCIngressSubnet2NATGateway68BB4190 
 38/44 | 18:25:27 | CREATE_COMPLETE      | AWS::EC2::NatGateway                  | VPC/IngressSubnet2/NATGateway (VPCIngressSubnet2NATGateway68BB4190) 
 38/44 | 18:25:30 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/ApplicationSubnet2/DefaultRoute (VPCApplicationSubnet2DefaultRouteC3680A52) 
 38/44 | 18:25:31 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/ApplicationSubnet2/DefaultRoute (VPCApplicationSubnet2DefaultRouteC3680A52) Resource creation Initiated 
 39/44 | 18:25:46 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/ApplicationSubnet2/DefaultRoute (VPCApplicationSubnet2DefaultRouteC3680A52) 
 40/44 | 18:25:58 | CREATE_COMPLETE      | AWS::EC2::NatGateway                  | VPC/IngressSubnet1/NATGateway (VPCIngressSubnet1NATGatewayEA4AE80E) 
 40/44 | 18:26:01 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/ApplicationSubnet1/DefaultRoute (VPCApplicationSubnet1DefaultRouteA4E47D36) 
 40/44 | 18:26:02 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/ApplicationSubnet1/DefaultRoute (VPCApplicationSubnet1DefaultRouteA4E47D36) Resource creation Initiated 
 41/44 | 18:26:14 | CREATE_COMPLETE      | AWS::EC2::NatGateway                  | VPC/IngressSubnet3/NATGateway (VPCIngressSubnet3NATGatewayF804BFD1) 
 41/44 | 18:26:17 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/ApplicationSubnet3/DefaultRoute (VPCApplicationSubnet3DefaultRoute33D8EB24) 
 42/44 | 18:26:18 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/ApplicationSubnet1/DefaultRoute (VPCApplicationSubnet1DefaultRouteA4E47D36) 
 42/44 | 18:26:18 | CREATE_IN_PROGRESS   | AWS::EC2::Route                       | VPC/ApplicationSubnet3/DefaultRoute (VPCApplicationSubnet3DefaultRoute33D8EB24) Resource creation Initiated 
 43/44 | 18:26:34 | CREATE_COMPLETE      | AWS::EC2::Route                       | VPC/ApplicationSubnet3/DefaultRoute (VPCApplicationSubnet3DefaultRoute33D8EB24) 
 44/44 | 18:26:36 | CREATE_COMPLETE      | AWS::CloudFormation::Stack            | AwsCdkVpcSample2Stack 
 
 ✅  AwsCdkVpcSample2Stack 
 
Stack ARN: 
arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:stack/AwsCdkVpcSample2Stack/b0fd2850-164b-11e9-b181-0a8788cf6370 
  • 作成されたCFnスタックを確認します。
$ aws cloudformation describe-stacks \ 
    --stack-name AwsCdkVpcSample2Stack 
{ 
    "Stacks": [ 
        { 
            "StackId": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:stack/AwsCdkVpcSample2Stack/b0fd2850-164b-11e9-b181-0a8788cf6370", 
            "StackName": "AwsCdkVpcSample2Stack", 
            "ChangeSetId": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:changeSet/CDK-de63a38c-a4ee-4d73-bd58-6cbb18575ace/4fd4d238-9249-4be4-9ecb-90523dff8df5", 
            "CreationTime": "2019-01-12T09:23:15.969Z", 
            "LastUpdatedTime": "2019-01-12T09:23:21.476Z", 
            "RollbackConfiguration": {}, 
            "StackStatus": "CREATE_COMPLETE", 
            "DisableRollback": false, 
            "NotificationARNs": [], 
            "Capabilities": [ 
                "CAPABILITY_IAM", 
                "CAPABILITY_NAMED_IAM" 
            ], 
            "Tags": [], 
            "EnableTerminationProtection": false, 
            "DriftInformation": { 
                "StackDriftStatus": "NOT_CHECKED" 
            } 
        } 
    ] 
} 
  • VPC IDを確認します。
$ aws cloudformation describe-stack-resources \ 
    --stack-name AwsCdkVpcSample2Stack \ 
    --query StackResources[?ResourceType==\`AWS::EC2::VPC\`] 
 
[ 
    { 
        "StackName": "AwsCdkVpcSample2Stack", 
        "StackId": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:stack/AwsCdkVpcSample2Stack/b0fd2850-164b-11e9-b181-0a8788cf6370", 
        "LogicalResourceId": "VPCB9E5F0B4", 
        "PhysicalResourceId": "vpc-07d7263312dbe87b6", 
        "ResourceType": "AWS::EC2::VPC", 
        "Timestamp": "2019-01-12T09:23:44.808Z", 
        "ResourceStatus": "CREATE_COMPLETE", 
        "DriftInformation": { 
            "StackResourceDriftStatus": "NOT_CHECKED" 
        } 
    } 
] 
  • VPCを確認します。
$ aws ec2 describe-vpcs --vpc-ids vpc-07d7263312dbe87b6 
{ 
    "Vpcs": [ 
        { 
            "CidrBlock": "10.0.0.0/16", 
            "DhcpOptionsId": "dopt-a74006c0", 
            "State": "available", 
            "VpcId": "vpc-07d7263312dbe87b6", 
            "OwnerId": "xxxxxxxxxxxx", 
            "InstanceTenancy": "default", 
            "CidrBlockAssociationSet": [ 
                { 
                    "AssociationId": "vpc-cidr-assoc-0e77ce173e6641870", 
                    "CidrBlock": "10.0.0.0/16", 
                    "CidrBlockState": { 
                        "State": "associated" 
                    } 
                } 
            ], 
            "IsDefault": false, 
            "Tags": [ 
                { 
                    "Key": "Name", 
                    "Value": "AwsCdkVpcSample2Stack/VPC" 
                }, 
                { 
                    "Key": "aws:cloudformation:stack-name", 
                    "Value": "AwsCdkVpcSample2Stack" 
                }, 
                { 
                    "Key": "aws:cloudformation:stack-id", 
                    "Value": "arn:aws:cloudformation:ap-northeast-1:xxxxxxxxxxxx:stack/AwsCdkVpcSample2Stack/b0fd2850-164b-11e9-b181-0a8788cf6370" 
                }, 
                { 
                    "Key": "aws:cloudformation:logical-id", 
                    "Value": "VPCB9E5F0B4" 
                } 
            ] 
        } 
    ] 


まとめ

CDKを利用することにより、サブネットやルートテーブルの煩雑なCloudFormationテンプテートを記載しなくてもVPCを作成することができました。現実世界では空のVPCから独自の構成を作ることもあるためその場合はどういったコードになるのか試してみたいところです。またスタックに関する情報をExportして他スタックから参照させることもできるためそちらも要検証です。

コメント

このブログの人気の投稿

投稿時間:2021-06-17 22:08:45 RSSフィード2021-06-17 22:00 分まとめ(2089件)

投稿時間:2021-06-20 02:06:12 RSSフィード2021-06-20 02:00 分まとめ(3871件)

投稿時間:2021-06-17 05:05:34 RSSフィード2021-06-17 05:00 分まとめ(1274件)