首页 > 解决方案 > AWS CloudFormation VPC CIDR 分配给安全组

问题描述

当我选择 VPC 网络时,如何将 VPC 的 CIDR 分配给安全组?

Parameters:
  VpcId:
    Type: 'AWS::EC2::VPC::Id'
    Description: VpcId of your existing Virtual Private Cloud (VPC)
    ConstraintDescription: must be the VPC Id of an existing Virtual Private Cloud.

  EC2SecurityGroup:
      Type: 'AWS::EC2::SecurityGroup'
      Properties:
        VpcId: !Ref VpcId
        GroupDescription: SecurityGroup
        SecurityGroupIngress:
          - IpProtocol: tcp
            FromPort: '22'
            ToPort: '22'
            CidrIp: 

感谢您的帮助。

标签: amazon-web-servicesamazon-cloudformationaws-cloudformation-custom-resource

解决方案


您无法根据作为参数传递的 Id 获取 VPC CIDR 范围。您要么必须将CIDR 作为第二个参数传递,要么构建一个自定义资源来为您执行此操作。

自定义资源将是一个lambda 函数,它将 VPC id 作为输入参数。然后使用 AWS SDK,该函数将查询 VPC 并将其 CIDR 返回到您的 CloudFormation 以在您的安全组中使用。


推荐阅读