gpt4 book ai didi

python - 如何将扩展策略添加到对流层的 cloudformation 中?

转载 作者:太空宇宙 更新时间:2023-11-03 17:54:27 24 4
gpt4 key购买 nike

我创建了一个 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())

关于python - 如何将扩展策略添加到对流层的 cloudformation 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28683435/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com