Skip to content

Instantly share code, notes, and snippets.

@a1k0u
Created April 1, 2024 18:20
Show Gist options
  • Save a1k0u/2af746def40b338d138f9a446f46665e to your computer and use it in GitHub Desktop.
Save a1k0u/2af746def40b338d138f9a446f46665e to your computer and use it in GitHub Desktop.
Adding tags to an Amazon ECR repository resource. If the tag from the list does not exist, it will be added to the tag set. If the tag has a different value, it will be changed in the repository tag set.
import boto3
TAGS_TO_ADD = [
{
"Key": "team",
"Value": "DevOps"
},
]
client = boto3.client("ecr")
paginator = client.get_paginator('describe_repositories')
for page in paginator.paginate():
repositories = page["repositories"]
for repository in repositories:
client.tag_resource(resourceArn=repository["repositoryArn"], tags=TAGS_TO_ADD)
print(f"Finished update {len(repositories)} repositories")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment