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: 

谢谢你的帮助。

不能根据作为参数传递的VPC CIDR范围的Id来获取VPC的CIDR范围。您必须将CIDR作为第二个参数传递,或者构造一个自定义资源来为您执行此操作。

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

最新更新