# 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
)