【问题标题】:Controlling DB Security Group Port Access via Cloud Formation通过 Cloud Formation 控制数据库安全组端口访问
【发布时间】:2021-02-26 13:32:58
【问题描述】:

我正在尝试创建一个满足以下条件的安全组:

一个名为 WordpressDbSecurityGroup 的安全组,它允许从 WebServerSecurityGroup 对标准 MySQL 端口进行传入访问

下面是如何使用 WordPressDbSecurityGroup 和 WebServerSecurityGroup。当我去构建堆栈时,我收到以下错误:

“遇到不受支持的属性 FromPort”

有人能解释一下原因吗?我在the documentation 中找不到任何关于如何为 dbsecurity 组指定从端口访问的内容。

        "WebServerSecurityGroup": {
        "Type": "AWS::EC2::SecurityGroup",
        "Properties": {
            "VpcId": {
                "Ref": "wordpressVpc"
            },
            "GroupDescription": "Allow access from HTTP and SSH traffic",
            "SecurityGroupIngress": [
                {
                    "IpProtocol": "tcp",
                    "FromPort": "80",
                    "ToPort": "80",
                    "CidrIp": "0.0.0.0/0"
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": "80",
                    "ToPort": "3306",
                    "CidrIp": "0.0.0.0/0"
                },
                {
                    "IpProtocol": "tcp",
                    "FromPort": "22",
                    "ToPort": "22",
                    "CidrIp": {
                        "Ref": "YourIp"
                    }
                }
            ]
        }
    },

        "wordpressDBSecurityGroup": {
        "Type": "AWS::RDS::DBSecurityGroup",
        "Properties": {
            "EC2VpcId": {
                "Ref": "wordpressVpc"
            },
            "GroupDescription": "Enable access to the db via port 3306.",
            "Tags": [
                {
                    "Key": "Name",
                    "Value": "wordpressDBSecurityGroup"
                }
            ],
            "DBSecurityGroupIngress": [
                {
                    "IpProtocol": "TCP",
                    "FromPort": "3306",
                    "ToPort": "3306",
                    "SourceSecurityGroupID" : {"Ref" : "WebServerSecurityGroup"}
                }
            ]
        },
        "DependsOn": [
            "WebServerSecurityGroup"
        ]
    },

【问题讨论】:

    标签: json amazon-web-services ansible amazon-cloudformation


    【解决方案1】:

    AWS::RDS::DBSecurityGroup 仅适用于 EC2-classic,即您在 2013 年之前拥有 RDS。现在您不再使用它,因为所有新 RDS 都在 VPC 中,而不是 EC2 -经典。

    因此,您应该为您的 RDS 数据库实例使用常规 AWS::EC2::SecurityGroup。然后你在VPCSecurityGroupsAWS::RDS::DBInstance 中引用它。

    【讨论】:

    • 谢谢。我尝试使用 REF 添加安全组,但出现错误。即:“属性 VPCSecurityGroups 的值必须是字符串列表类型”“VPCSecurityGroups”:{“Ref”:“wordpressDBSecurityGroup”},
    • @redwytnblak 错误信息说明了一切。哟必须使用字符串列表,而不仅仅是字符串。
    • @redwytnblak 我看到列表问题已解决。不过,如果我的回答有帮助,我们将不胜感激。
    猜你喜欢
    • 2011-07-24
    • 1970-01-01
    • 2016-10-30
    • 2021-08-25
    • 2010-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多