How do you work with tags in boto3?
IntermediateConceptboto3 & AWS automation
Answer
Most services represent tags as a list of {"Key": ..., "Value": ...} dicts; convert to a dict for lookups.
tags = {t["Key"]: t["Value"] for t in inst.get("Tags", [])}
ec2.create_tags(Resources=[iid], Tags=[{"Key": "Owner", "Value": "platform"}])
ec2.describe_instances(Filters=[{"Name": "tag:Environment", "Values": ["prod"]},
{"Name": "tag-key", "Values": ["Owner"]}])
Some services differ (S3 uses TagSet, Lambda uses a plain dict). The Resource Groups Tagging API (resourcegroupstaggingapi.get_resources) searches tags across services in one place.
More on boto3 & AWS automation
What is the difference between a boto3 Session, client and resource?BeginnerHow does boto3 find credentials?BeginnerHow does boto3 decide the region, and what is the gotcha with `AWS_REGION`?AdvancedWhy do you need paginators, and how do you use them?BeginnerWhat is JMESPath `search()` on paginators?AdvancedHow do you handle errors from boto3?Beginner