amazon-web-services - AWS Cloudformation !Ref SecurityGroup 返回无效 ID

标签 amazon-web-services aws-cloudformation aws-security-group

我想通过 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/

相关文章:

java - API 网关自定义授权方 : Control error message and code

amazon-web-services - 描述堆栈和列表堆栈之间的区别?

amazon-web-services - 将 Terraform 输出从一个模块传递到另一个模块

amazon-web-services - 使用 Amazon CloudFormation 安装 Windows 应用程序/扩展

amazon-web-services - AWS : Security Group Auto Scale

amazon-web-services - AWS Cloudformation : Use existing SG Cidr Range, 但端口号不同

amazon-web-services - 账户与azure AD关联后如何从Alexa获取accesstoken

amazon-web-services - AWS S3 存储桶策略显式拒绝

amazon-web-services - 如果 StringSet 不存在,则附加到或创建它

json - Eclipse:使用 Json 编辑器插件自动格式化 JSON 文件,例如 AWS Cloudformation Template