AWS CloudFormation VPC CIDR 分配给安全组
AWS CloudFormation VPC CIDR assign to Security Group
当我 select 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:
感谢您的帮助。
您无法根据作为参数传递的 ID 获取 VPC CIDR 范围。您要么必须将 CIDR 作为第二个参数 传递,要么构造一个 custom resource 来为您执行此操作。
自定义资源将是一个 lambda 函数,它将 VPC id 作为输入参数。然后使用 AWS SDK,该函数将查询 VPC 和 return 其 CIDR 到您的 CloudFormation 以用于您的安全组。
当我 select 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:
感谢您的帮助。
您无法根据作为参数传递的 ID 获取 VPC CIDR 范围。您要么必须将 CIDR 作为第二个参数 传递,要么构造一个 custom resource 来为您执行此操作。
自定义资源将是一个 lambda 函数,它将 VPC id 作为输入参数。然后使用 AWS SDK,该函数将查询 VPC 和 return 其 CIDR 到您的 CloudFormation 以用于您的安全组。