[英]how to tag an existing AWS autoscaling group with boto3
I'm trying to tag an existing autoscaling group, using Python and Boto3.我正在尝试使用 Python 和 Boto3 标记现有的自动缩放组。
I can definitely describe the ASGs by name:我绝对可以用名字来描述 ASG:
import boto3
asg_client = boto3.client("autoscaling")
asg_name = "foo-bar20220502044025104700000001"
response = asg_client.describe_auto_scaling_groups(AutoScalingGroupNames=[asg_name])
The problem I have with the create_or_update_tags()
and delete_tags()
methods is that they don't seem to accept a list of ASG names.我对
create_or_update_tags()
和delete_tags()
方法的问题是它们似乎不接受 ASG 名称列表。 Eg this doesn't work:例如这不起作用:
asg_client.create_or_update_tags(
AutoScalingGroupNames=[asg_name],
Tags=[my_tag]
)
To make it clear:说清楚:
The tag-related methods appear to be different from all the other ASG client methods in that they do not accept an ASG name, or list of names, as a parameter.与标签相关的方法似乎与所有其他 ASG 客户端方法不同,因为它们不接受 ASG 名称或名称列表作为参数。
You can do this, you just need provide a different input.你可以做到这一点,你只需要提供不同的输入。 The
ResourceId
of these client methods can be supplied with an ASG name.这些客户端方法的
ResourceId
可以与 ASG 名称一起提供。
Here is the boto3 docs for the create_or_update_tags
call. 这是
create_or_update_tags
调用的 boto3 文档。
Here's an example:这是一个例子:
asg_client.create_or_update_tags(
Tags=[
{
'ResourceId': asg_name,
'ResourceType': 'auto-scaling-group',
'Key': 'myTagKey',
'Value': 'myTagValue',
'PropagateAtLaunch': True
},
]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.