我有这个AWS :: EC2 :: SecurityGroup:

    "InstanceSecurityGroup" : {
        "Type" : "AWS::EC2::SecurityGroup",
        "Properties" : {
            "GroupDescription" : "Enable HTTP access on the configured port",
            "VpcId" : { "Ref" : "VpcId" },
            "SecurityGroupIngress" : [ {
                "IpProtocol" : "tcp",
                "FromPort" : { "Ref" : "WebServerPort" },
                "ToPort" : { "Ref" : "WebServerPort" },
                "SourceSecurityGroupId" : { "Ref" : "LoadBalancerSecurityGroup" }
            } ]
        }
    }


我有这个AWS :: RDS :: DBSecurityGroup

    "DBSecurityGroup": {
        "Type": "AWS::RDS::DBSecurityGroup",
        "Properties": {
            "DBSecurityGroupIngress": { "EC2SecurityGroupName": { "Ref": "InstanceSecurityGroup"} },
            "GroupDescription"      : "Frontend Access"
        }
    }


当我尝试调出该堆栈时,我得到:

Invalid security group , groupId=, groupName= sg-a381fdc6.


编辑1:多读一些内容表明我需要将AWS :: RDS :: DBSecurityGroup与我的VPC关联,所以我更改为:

    "DBSecurityGroup": {
        "Type": "AWS::RDS::DBSecurityGroup",
        "Properties": {
            "EC2VpcId" : { "Ref" : "VpcId" },
            "DBSecurityGroupIngress": { "EC2SecurityGroupName": { "Ref": "InstanceSecurityGroup"} },
            "GroupDescription"      : "Frontend Access"
        }
    }


当我拿起堆栈时,我得到

请参阅授权DBSecurityGroup入口的文档。对于VPC,需要EC2SecurityGroupId。要仅授权此请求的源地址(而不授权其他地址),请传递205.251.233.35/32作为CIDRIP参数。

EC2SecurityGroupId是安全组的ID,而不是安全组的名称,并且该ID是在我的控制范围之外分配的,所以我不知道在此输入什么值。

如何在VPC上下文中将AWS :: EC2 :: DBSecurityGroup连接到我的AWS :: RDS :: DBSecurityGroup?

最佳答案

问题是您的{ "Ref": "InstanceSecurityGroup"}不只包含ID名称。要保留EC2SecurityGroupId,请使用Fn::GetAtt

DBSecurityGroup的模板应如下所示(注意Ref已被Fn :: GetAtt替换:

"DBSecurityGroup": {
"Type": "AWS::RDS::DBSecurityGroup",
"Properties": {
   "EC2VpcId"              : { "Ref" : "VpcId" },
   "DBSecurityGroupIngress": { "EC2SecurityGroupId": { "Fn::GetAtt" : [ "InstanceSecurityGroup", "GroupId" ] } },
   "GroupDescription"      : "Frontend Access"
}

08-07 21:55