AWS CDK PublicSubnet无法创建Internet网关

时间:2020-08-30 18:50:14

标签: amazon-web-services aws-cdk

CDK是1.61.1版

然后在 vpc 资源中内联创建子网,而我正尝试使用 PublicSubnet 构造来创建子网。我不希望vpc构造创建任何子网。如果我尝试这样做:

from aws_cdk import (
    aws_s3 as s3,
    aws_ec2 as ec2,
    core,
)

class HelloCdkStack(core.Stack):

    def __init__(self, scope: core.Construct, id: str, **kwargs) -> None:
        super().__init__(scope, id, **kwargs)


        ## VPC
        vpc = ec2.Vpc(self, "vpc1",
            cidr                 = "172.20.0.0/23",
            nat_gateways         = 0,
            enable_dns_hostnames = True,
            enable_dns_support   = True,

            subnet_configuration = []
            )

        subnet = ec2.PublicSubnet(self, "subnet1",
            vpc_id                  = vpc.vpc_id,
            availability_zone       = vpc.availability_zones[0],
            cidr_block              = "172.20.0.0/24",
            map_public_ip_on_launch = True
        )

已创建子网和路由表,但没有Internet网关或默认路由:

vpcA2121C38:
  Type: AWS::EC2::VPC
  Properties:
    CidrBlock: 172.20.0.0/23
    EnableDnsHostnames: true
    EnableDnsSupport: true
    InstanceTenancy: default
    Tags:
      - Key: Name
        Value: hello-cdk/vpc
  Metadata:
    aws:cdk:path: hello-cdk/vpc/Resource
subnetSubnet39D20FD5:
  Type: AWS::EC2::Subnet
  Properties:
    CidrBlock: 172.20.0.0/24
    VpcId:
      Ref: vpcA2121C38
    AvailabilityZone:
      Fn::Select:
        - 0
        - Fn::GetAZs: ""
    MapPublicIpOnLaunch: true
    Tags:
      - Key: Name
        Value: hello-cdk/subnet
  Metadata:
    aws:cdk:path: hello-cdk/subnet/Subnet
subnetRouteTable8BC76A23:
  Type: AWS::EC2::RouteTable
  Properties:
    VpcId:
      Ref: vpcA2121C38
    Tags:
      - Key: Name
        Value: hello-cdk/subnet
  Metadata:
    aws:cdk:path: hello-cdk/subnet/RouteTable
subnetRouteTableAssociation94267163:
  Type: AWS::EC2::SubnetRouteTableAssociation
  Properties:
    RouteTableId:
      Ref: subnetRouteTable8BC76A23
    SubnetId:
      Ref: subnetSubnet39D20FD5
  Metadata:
    aws:cdk:path: hello-cdk/subnet/RouteTableAssociation

实际上,如果我使用 PublicSubnet PrivateSubnet Subnet 结构,创建的资源似乎没有什么不同。 如果我在vpc构造内添加一个公共子网,则网关确实会创建。

0 个答案:

没有答案