Создайте тег на каждом экземпляре ec2, если он не существует. Обновить тег новым значением, если оно существует

new_list = list(old_list)

0
задан aaa 30 March 2019 в 21:06
поделиться

1 ответ

Вот код, который должен это сделать:

import boto3
client = boto3.client('ec2', region_name='ap-southeast-2')

def handler(event, context):

    # Get a list of instances
    response = client.describe_instances()

    # For each instance
    for reservation in response['Reservations']:
        for instance in reservation['Instances']:

            # Extract existing tags
            tags = [tag['Key'] for tag in instance['Tags']]

            if 'MyID' not in tags:
                # Add a tag
                tag_response = client.create_tags(
                    Resources=[instance['InstanceId']],
                    Tags=[{'Key': 'MyID', 'Value': ''}]
                )
0
ответ дан John Rotenstein 30 March 2019 в 21:06
поделиться
Другие вопросы по тегам:

Похожие вопросы: