我想通过 cloudformation 部署具有 SecurityGroup 入口规则的 SecurityGroup。
我目前在 yaml 文件中使用它:
Security
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Securitygroup with access to itself
SecurityIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !Ref Security
SourceSecurityGroupId: !Ref Security
IpProtocol: tcp
FromPort: -1
这会给我一个错误,指出 SucurityGroupId 格式错误。创建 SecurityIngress 时会发生该错误。请注意,我已将堆栈名称更改为“Stackname”。
Invalid Id: \"Stackname-Security-N12M8127812\" (expecting \"sg-\")
所以我猜 !Ref 不会返回 SecurityGroup 的 ID,而是返回名称。 有办法获取 id 吗?
最佳答案
使用!Ref
将返回资源名称。 documentation中明确提到了这一点。您需要使用 !GetAtt
获取资源属性之一,包括安全组 ID。
SourceSecurityGroupId: !GetAtt Security.GroupId
关于amazon-web-services - AWS Cloudformation !Ref SecurityGroup 返回无效 ID,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57176869/