1

我创建了一个 python 对流层脚本,总体上运行良好。我刚刚添加了一段新代码,以将策略添加到自动缩放组以发出警报。

代码如下所示:

tintScaleDown = autoscaling.ScalingPolicy("tintScaleDown1")
tintScaleDown.AdjustmentType = "ChangeInCapacity"
tintScaleDown.AutoScalingGroupName(Ref("tintASG"))
tintScaleDown.Cooldown = "900"
tintScaleDown.ScalingAdjustment = "1"
t.add_resource(tintScaleDown)

错误是:

回溯(最后一次调用):文件“inPowered.py”,第 395 行,在 tintScaleDown.AutoScalingGroupName(Ref("tintASG")) 文件“ /usr/lib/python2.7/site-packages/troposphere/init .py ",第 79 行,在getattr中 引发 AttributeError(name)

参考应该已经建立在这一行:

asg = autoscaling.AutoScalingGroup("tintASG")

CloudFormation 脚本的部分应如下所示:

            "tintScaleDown1": {
                    "Type": "AWS::AutoScaling::ScalingPolicy",
                    "Properties": {
            "AdjustmentType": "ChangeInCapacity",
                            "AutoScalingGroupName": {
                                    "Ref": "tintASG"
                            },
                            "Cooldown": "900",
                            "ScalingAdjustment": "-1"
                    }
    },

建议?

4

2 回答 2

1

我会这样回答。

from troposphere import Template, autoscaling
t = Template() # Add the template object as "t"
#Create the Autoscaling object as "asg" within the creation of the object, call the template to make the template format
asg = t.add_resource(autoscaling.ScalingPolicy(
    "tintScaleDown1",
    AdjustmentType="ChangeInCapacity",
    AutoScalingGroupName=Ref(tintASG),
    Cooldon="900",
    ScalingAdjustment="-1",

))
print(t.to_json())
于 2015-05-22T15:05:06.507 回答
0

好的,所以对流层的创建者 Mark Peek 指出我的语法不正确。解决方案是

tintScaleDown.AutoScalingGroupName(Ref("tintASG"))

应该

tintScaleDown.AutoScalingGroupName = Ref("tintASG")
于 2015-02-24T05:10:30.447 回答