使用AWS CDK添加和链接资源

时间:2019-09-04 13:37:13

标签: amazon-web-services security subnet aws-cdk

我一直在使用AWS CDK进行部署,并部署了一个具有2AZ的6个子网(2个公有和4个私有)的VPC,在其AZ内具有CIDR:

  1. 私有子网10.0.1.0/24
  2. 私有子网10.0.2.0/24
  3. 私有子网10.0.3.0/24
  4. 私有子网10.0.4.0/24

CDK部署失败。

我每天都在发现新事物,CDK并不那么简单,也没有教程。大多数情况下,当您添加资源时,它只会避免使用资源,并部署通常的资源。

from aws_cdk import core,aws_ec2,aws_ecs,aws_ecs_patterns,aws_rds,aws_dynamodb

class TestCdkStack(core.Stack):

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

        # The code that defines your stack goes here

        subnets= []

        subnets.append(aws_ec2.SubnetConfiguration(name = "***-Web-Shared-Public-Subnet", subnet_type = aws_ec2.SubnetType.PUBLIC, cidr_mask = 20))
        subnets.append(aws_ec2.SubnetConfiguration(name = "***-Web-Shared-DBa-Private-Subnet", subnet_type = aws_ec2.SubnetType.PRIVATE, cidr_mask = 24))
        subnets.append(aws_ec2.SubnetConfiguration(name = "***-Web-Shared-ADa-Private-Subnet", subnet_type = aws_ec2.SubnetType.PRIVATE, cidr_mask = 24))

        vpc=aws_ec2.Vpc(self, '***-Web-Shared-VPC',
                        max_azs=2,
                        nat_gateways=2,
                        cidr='*.*.*.*/16',
                        enable_dns_support=True,
                        enable_dns_hostnames=True,
                        subnet_configuration=subnets,
        )
VPC
***-Web-Shared-VPC      10.0.0.0/16

Subnets
***-Web-Shared-DBa-Private-Subnet     10.0.1.0/24
***-Web-Shared-DBb-Private-Subnet     10.0.2.0/24
***-Web-Shared-ADa-Private-Subnet     10.0.3.0/24
***-Web-Shared-ADb-Private-Subnet     10.0.4.0/24

Route Tables
***-Web-Shared-DBa-Private-Route-Table
***-Web-Shared-ADa-Private-Route-Table

NaCl
***-Web-Shared-DBa-Private-NACL
***-Web-Shared-ADa-Private-NACL

Security Group
***-Web-Shared-DBa-Private-Security-Group
***-Web-Shared-ADa-Private-Security-Group

要求:

  • 启用DNS主机名
  • 确保自动分配的公共IP位于公共子网中
  • 在NACL上,传入和传出规则必须为100,以允许所有流量。

我想指定IP,路由表,SG和NACL。但我无法解决这个问题。

相反,这些是我获得的IP:

10.0.0.0/20,
10.0.16.0/20,
10.0.32.0/24,
10.0.33.0/24,
10.0.34.0/24,
10.0.35.0/24

0 个答案:

没有答案