Boto: How do I use the 'tag' parameter of the AutoScalingGroup method?

自古美人都是妖i 提交于 2020-01-05 07:59:46

问题


The following code works. In other words, there is no error returned and a group is created. However, the instances launched by this group will not have a Name tag.

AS_GROUP = AutoScalingGroup(
    group_name=AS_GROUP_NAME,
    availability_zones=ZONE_LIST,
    launch_config=LAUNCH_CONFIG_NAME,
    min_size=GROUP_MIN_SIZE,
    max_size=GROUP_MAX_SIZE,
    default_cooldown=DEFAULT_COOLDOWN,
    desired_capacity=DESIRED_CAPACITY,
    tag=[Tag(
            key='Name',
            value='ASG Minion',
            propagate_at_launch=True,
            resource_id=AS_GROUP_NAME)],
    )
AS_CONNECTION.create_auto_scaling_group(AS_GROUP)

I have tried the Tag method without the resource_id.

[Tag(key="Name", value="ASGMinion", propagate_at_launch=True)]

Other obviously wrong ways I have also tried:

tag='k=Name, v=ASGMinion, p=true',
tag=['k=Name, v=ASGMinion, p=true'],
tag=[Tag('k=Name, v=ASGMinion, p=true')],

No worky.

Of course, I can run this after the group is already created:

tag = Tag(key='Name', value=tag_name, propagate_at_launch=True, resource_id=groups[group_number].name)
asConnection.create_or_update_tags([tag])

But that defeats the point of the tag parameter in the AutoScalingGroup method.


回答1:


Well, this is rather embarrassing. The main problem was that the correct name of the parameter is tags and not tag. Once I got that sorted out I was able to run through and find which value this parameter was looking for. This is what works:

tags=[Tag(
        key='Name',
        value='ASG Minion',
        propagate_at_launch=True,
        resource_id=AS_GROUP_NAME)],
)

I tried it also without the resource_id and it complained with Invalid resourceID: None. So the group name needs to be specified in the tag even if the group is the being created at the same time. Hopefully this is helpful to someone else.



来源:https://stackoverflow.com/questions/21766867/boto-how-do-i-use-the-tag-parameter-of-the-autoscalinggroup-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!