我创建了一个 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"
}
},
建议?
我会这样回答。
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())
我是一名优秀的程序员,十分优秀!