是的,底层资源也需要标记,但是标记必须通过AWS服务目录中的其他资源来实现。例如,您可以为SageMaker Notebook实例创建标记,并在实例中使用的其他资源上使用相同的标记。下面是在SageMaker Notebook实例上创建和使用标记的示例代码:
import boto3
# Set the notebook instance name and the desired tags
notebook_instance_name = 'my_notebook_instance'
tags = [{'Key': 'Environment', 'Value': 'Production'}, {'Key': 'Department', 'Value': 'Data Science'}]
# Create a SageMaker client
sagemaker = boto3.client('sagemaker')
# Get the ARN of the notebook instance
response = sagemaker.describe_notebook_instance(NotebookInstanceName=notebook_instance_name)
notebook_instance_arn = response['NotebookInstanceArn']
# Create tags for the notebook instance
sagemaker.create_tags(ResourceArn=notebook_instance_arn, Tags=tags)
# Use the same tags for other resources used by the notebook instance
# For example, a training job:
training_job_name = 'my_training_job'
sagemaker.add_tags(ResourceArn='arn:aws:sagemaker:us-east-1:123456789012:training-job/' + training_job_name, Tags=tags)