【问题标题】:AWS CloudFormation VPC CIDR assign to Security GroupAWS CloudFormation VPC CIDR 分配给安全组
【发布时间】:2021-01-14 11:54:45
【问题描述】:

当我选择 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-services amazon-cloudformation aws-cloudformation-custom-resource


    【解决方案1】:

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

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

    【讨论】:

    • @Mr.Tux 没问题。如果答案有帮助,我们将不胜感激。
    猜你喜欢
    • 2015-08-01
    • 1970-01-01
    • 2021-06-28
    • 1970-01-01
    • 2016-05-12
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 2017-08-08
    相关资源
    最近更新 更多