简体   繁体   English

如何使用 boto3 标记现有的 AWS 自动缩放组

[英]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 ASG already exists, I am not creating it here ASG 已经存在,我不会在这里创建它
  • I do not want to make any other changes to the ASG我不想对 ASG 进行任何其他更改
  • all I want is be able to tag an ASG if I know its name如果我知道它的名字,我想要的只是能够标记一个 ASG
  • I need to use boto3 from Python for this为此,我需要使用 Python 中的 boto3

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.

相关问题 如何使用 Boto3 检查 ELB 是否与任何自动缩放组相关联 - How to check an ELB is associated with any autoscaling group using Boto3 Lambda function 使用 boto3 删除具有特定标签的自动缩放组 - Lambda function to delete autoscaling groups with a specific tag using boto3 如何使用 boto3(lambda) 对 AWS dynamodb 表进行分组并获取分区键的最新值? - how to group AWS dynamodb table and get latest value of partition key using boto3(lambda)? 使用 boto3 查询 AWS Cloudwatch 日志组订阅 - Querying AWS Cloudwatch Log Group Subscriptions Using boto3 使用 boto3 自动标记 aws 实例 - autotagging aws instance with boto3 如何使用 Boto3 库在 AWS Glue 中创建工作流程? - How to create a workflow in AWS Glue using Boto3 library? 如何在 python 中使用 boto3 更新 AWS Gamelift 脚本? - How do I update an AWS Gamelift script with boto3 in python? 如何使用 boto3 列出 Cloudwatch 中的所有日志组 - How to list all the log group in Cloudwatch using boto3 如何使用 boto3 运行现有的 EMR 无服务器作业? - How to run existing EMR serverless job with boto3? AWS boto3 如何从密钥中获取元数据? - AWS boto3 how to get the metadata from the key?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM