【问题标题】:Setting DBSecurityGroupIngress in Troposphere在对流层中设置 DBSecurityGroupIngress
【发布时间】:2019-02-02 16:09:36
【问题描述】:

想要将多个 CIDRip 添加到我的数据库安全组 错误:

CidrIp=Ref(AppSecurityGroup)),
TypeError: __init__() takes at least 2 arguments (1 given)

我认为这很容易,但我被困在这里并感到困惑。

DBSecurityGroup = t.add_resource(
    rds.DBSecurityGroup(
        'DBSecurityGroup',
        GroupDescription='Enable access on the inbound port',
        DBSecurityGroupIngess=[
            rds.DBSecurityGroup(
                IpProtocol='tcp',
                FromPort='3306',
                ToPort='3306',
                CidrIp=Ref(AppSecurityGroup)),
            rds.DBSecurityGroup(
                IpProtocol='tcp',
                FromPort='3306',
                ToPort='3306',
                CidrIp=Ref(CalcSecurityGroup)),
            rds.DBSecurityGroup(
                IpProtocol='tcp',
                FromPort='3306',
                ToPort='3306',
                CidrIp=Ref(CIDRSupport))],
        VpcId=Ref(VPC),
        Tags=Tags(
            Name=Join("", [Ref("AWS::StackName"), "-DB-SG"]),
        )
    ))

现在我需要在 6379 端口入站到 Calc-SG、App-SG 和 CIDRSupport。

如何在 SG 中定义它?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation troposphere


    【解决方案1】:

    您正在处理CidrIp 的DBSecurityGroup 类没有的属性。该类定义为:

    class RDSSecurityGroup(AWSProperty):
        props = {
            'CIDRIP': (basestring, False),
            'EC2SecurityGroupId': (basestring, False),
            'EC2SecurityGroupName': (basestring, False),
            'EC2SecurityGroupOwnerId': (basestring, False),
        }   
    
    class DBSecurityGroup(AWSObject):
        resource_type = "AWS::RDS::DBSecurityGroup"
    
        props = {
            'EC2VpcId': (basestring, False),
            'DBSecurityGroupIngress': (list, True),
            'GroupDescription': (basestring, True),
            'Tags': ((Tags, list), False),
        }
    

    来自源代码here。

    你想说的是:

    DBSecurityGroup = t.add_resource(
        rds.DBSecurityGroup(
            "DBSecurityGroup",
            GroupDescription="Enable access on the inbound port",
            DBSecurityGroupIngress=[
                rds.RDSSecurityGroup(EC2SecurityGroupId=Ref(AppSecurityGroup)),
                rds.RDSSecurityGroup(EC2SecurityGroupId=Ref(CalcSecurityGroup)),
                rds.RDSSecurityGroup(EC2SecurityGroupId=Ref(CIDRSupport))],
            EC2VpcId=Ref(VPC),
            Tags=Tags(
                Name=Join("", [Ref("AWS::StackName"), "-DB-SG"]),
            )
        ))
    

    我会注意到对流层的RDSSecurityGroup 对应于“RDS Security Group Rule”。命名不一致令人困惑。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-08-16
    • 2016-07-05
    • 2017-07-25
    • 1970-01-01
    • 2022-10-01
    • 2020-05-28
    • 2021-11-01
    相关资源
    最近更新 更多