如何使用AutoScalingGroup方法的

如何使用AutoScalingGroup方法的

本文介绍了Boto:如何使用AutoScalingGroup方法的'tag'参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下代码有效.换句话说,没有错误返回,并且创建了一个组.但是,由该组启动的实例将没有Name标记.

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)

我尝试了不使用resource_idTag方法.

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')],

没有工作.

当然,我可以在创建组之后运行它:

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])

但是这使AutoScalingGroup方法中tag参数的含义失效.

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

推荐答案

好吧,这很尴尬.主要问题是参数的正确名称是tags而不是tag.一旦解决了这个问题,我便可以遍历并找到此参数要查找的值.这是可行的:

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)],
)

我也尝试了不使用resource_id的情况,并且抱怨Invalid resourceID: None.因此,即使正在同时创建组,也需要在标签中指定组名.希望这对其他人有帮助.

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.

这篇关于Boto:如何使用AutoScalingGroup方法的'tag'参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 04:47