问题
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