cloudformation中如何自引用SourceSecurityGroup?

How to self-reference SourceSecurityGroup in cloudformation?

我有这个代码:

Mysql:
Type: 'AWS::EC2::SecurityGroup'
Properties:
  GroupName: Mysql
  GroupDescription: MySQL security group
  SecurityGroupIngress:
    - IpProtocol: tcp
      FromPort: 3306
      SourceSecurityGroupName: Mysql
      ToPort: 3306
  Tags:
    - Key: Name
      Value: MySQL 3306 Access
  VpcId: !ImportValue VPC-ID

这个returns这个错误: 默认 VPC 'vpc-xxx' 中不存在安全组 'Mysql'(服务:AmazonEC2;状态代码:400;错误代码:InvalidGroup.NotFound;请求 ID:xxxxx)

我有机会看到安全组在哪里,如果你可以自己参考的话,但我无法实现这个规则。有人遇到过同样的问题吗?

当您需要自引用安全组或相互引用的安全组时,请使用 SecurityGroupIngress 或 SecurityGroupEgress 资源。

https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ec2-security-group-ingress.html

基本上您将创建安全组,然后向其添加规则。