how to tag an existing autoscaling group using boto3

0

I'm trying to tag an existing autoscaling group, using Python and Boto3.

I can definitely describe the ASGs by name:

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. E.g. 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
  • I do not want to make any other changes to the ASG
  • all I want is be able to tag an ASG if I know its name
  • I need to use boto3 from Python for this

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.

1 Answer
1
Accepted Answer

Thank you for the detailed description.

The ASG name should be specified as ResourceId in the Tags:

response = client.create_or_update_tags(
    Tags=[
        {
            'Key': 'Role',
            'PropagateAtLaunch': True,
            'ResourceId': 'my-auto-scaling-group',
            'ResourceType': 'auto-scaling-group',
            'Value': 'WebServer',
        }
    ],
)

print(response)

Refer to https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/autoscaling.html#AutoScaling.Client.create_or_update_tags for more information.

AWS
weidi
answered a year ago
  • @weidi - that was it! Sorry for the simple question, after coding all day I missed the obvious thing in the docs. Thank you.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions