1

I've create a python troposphere script that's been working quite well overall. I just added in a new piece of code to add a policy to the autoscaling group for an alarm.

The code looks like:

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

The error is:

Traceback (most recent call last): File "inPowered.py", line 395, in tintScaleDown.AutoScalingGroupName(Ref("tintASG")) File "/usr/lib/python2.7/site-packages/troposphere/init.py", line 79, in getattr raise AttributeError(name)

The Reference should have been established in this line:

asg = autoscaling.AutoScalingGroup("tintASG")

The section of the CloudFormation script should look like:

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

Suggestions?

efreedom
  • 253
  • 3
  • 8

2 Answers2

1

I would answer that like this.

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())
Mo Ali
  • 639
  • 1
  • 6
  • 17
0

OK, so Mark Peek, creator of troposphere, pointed out that my syntax was incorrect. The solution is

tintScaleDown.AutoScalingGroupName(Ref("tintASG"))

should be

tintScaleDown.AutoScalingGroupName = Ref("tintASG")
efreedom
  • 253
  • 3
  • 8