Reputation: 1
I am fairly new to AWS Python Boto3. I am trying to figure a way to replace existing tags value with a different value.
import boto3
session = boto3.session.Session(aws_access_key_id=aws_access_id, aws_secret_access_key=aws_secret, region_name='us-east-1')
ec2 = session.resource('ec2')
instances = ec2.instances.filter(
Filters=[{'Name':'tag:1',
'Values':['2']}
])
The code above will find all instances with the mentioned tag but I am not sure how to replace the tags with a different value.
Any help is appreciated.
Upvotes: 0
Views: 2028
Reputation: 78850
Use create_tags. Despite the 'create' name, it also updates tags.
Example:
import boto3
client = boto3.client('ec2')
response = client.create_tags(
Resources=[
'i-0397e32da88889999',
],
Tags=[
{
'Key': 'Env',
'Value': 'QA'
},
]
)
Upvotes: 1