Tag EIP with Boto3

Viewed 931

Is it possible to tag an Elastic IP address with boto3? I know you can tag them through the console and I have tagged many of them this way but I can seem to find any documentation on tagging them with boto3.

I this is not possible with boto3 is there some other library I can use to accomplish this?

1 Answers

The boto3 library offers a generic create_tags method that can be used to apply tags to a number of different types of AWS resources, including Elastic IPs. Here's an example of how to use it:

import boto3

ec2 = boto3.client('ec2', region_name='us-east-1')

response = ec2.create_tags(
    Resources=[
        'eipalloc-094ca1234de5abcd',
    ],
    Tags=[
        {
            'Key': 'Description',
            'Value': 'Production EIP'
        },
    ]
)

Note: this adds the tag Description=Production EIP to whatever tags are already present on the resource (or it overwrites the Description tag if it already exists).

Related