Skip to content

Instantly share code, notes, and snippets.

@andreburto
Created June 25, 2023 16:05
Show Gist options
  • Save andreburto/34095ea8e44371d13c80df088782e898 to your computer and use it in GitHub Desktop.
Save andreburto/34095ea8e44371d13c80df088782e898 to your computer and use it in GitHub Desktop.
import argparse
import boto3
from datetime import datetime
DEFAULT_REGION = "us-east-1"
DEFAULT_RESOURCE_LIST = ["arn:aws:s3:::cow.mothersect.info",
"arn:aws:lambda:us-east-1:441882069681:function:YvonneGo", ]
def setup_args():
args = argparse.ArgumentParser(description="Tag Test")
args.add_argument("--profile", dest="profile", required=False)
args.add_argument("--region", dest="region", required=False, default=DEFAULT_REGION)
return args.parse_args()
def main():
args = setup_args()
if args.profile:
session = boto3.session.Session(profile_name=args.profile, region_name=args.region)
else:
session = boto3.session.Session(region_name=args.region)
tag_client = session.client("resourcegroupstaggingapi")
tags = tag_client.get_resources(ResourceARNList=DEFAULT_RESOURCE_LIST)
print(f"Tags: {tags}")
dt_tag = datetime.now().strftime("%Y-%m-%d-%H-%M-%S")
update_tags = tag_client.tag_resources(ResourceARNList=DEFAULT_RESOURCE_LIST,
Tags={"dt": dt_tag})
print(f"Update Tags: {update_tags}")
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment