79263739

Date: 2024-12-09 03:04:49
Score: 0.5
Natty:
Report link
    # Retrieve all tags from the source file system with pagination
    all_tags = []
    next_token = None

    while True:
        response = efs_client.list_tags_for_resource(
            ResourceId=source_file_system_id,
            MaxResults=100,
            NextToken=next_token
        )
        all_tags.extend(response["Tags"])
        next_token = response.get("NextToken")
        if not next_token:
            break

    # Optionally add or overwrite the 'Name' tag with NewFileSystemName
    if new_file_system_name:
        all_tags = [tag for tag in all_tags if tag["Key"] != "Name"]  # Remove existing 'Name' tag, if any
        all_tags.append({"Key": "Name", "Value": new_file_system_name})

    # Apply the tags to the target file system
    efs_client.tag_resource(
        ResourceId=target_file_system_id,
        Tags=all_tags
    )
Reasons:
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (1):
Posted by: Avasek Monster