Skip to content

Question about SageMaker Notebook job tags and username

0

We are using cloudformation to create jupyter notebook with tags we want. While when we execute Estimators, it will create a training job without any tags. We tried to copy tags from notebook instance to the job using python. However, due to "aws:cloudformation:stack-name" is reserved, it will fail to execute. Is there anyone know anyway to inherit tag from notebook instance? The way we copy tags. It won't work unless we skip "aws:cloudformation:*" tags.

import json

with open('/opt/ml/metadata/resource-metadata.json', 'r') as logs:
    meta_data = json.load(logs)

org_tags = boto3.client("sagemaker").list_tags(ResourceArn = meta_data['ResourceArn'])['Tags']
tags = {}
for org_tag in org_tags:
    tags[org_tag['Key']] = org_tag['Value']
tabular_estimator = Estimator(
    role=aws_role,
    image_uri=train_image_uri,
    source_dir=train_source_uri,
    model_uri=train_model_uri,
    entry_point="transfer_learning.py",
    instance_count=1,
    instance_type=training_instance_type,
    max_run=360000,
    hyperparameters=hyperparameters,
    output_path=s3_output_location,
    tags = tags 
)
# Launch a SageMaker Training job by passing the S3 path of the training data
predictor = estimator.fit(
    {
        "training": training_dataset_s3_path,
        "validation": validation_dataset_s3_path,
    }, logs=False, job_name=training_job_name
)

Also we we check the cloudtrail the username is also "sagemaker". Is there anyway to make the username link back to who execute the notebook?

cloudtrail log of create job

Thank you

1 Answer
0

As you wrote, "aws:" prefix in the resource tag names is reserved for AWS use, so you cannot use it. You can take this approach:

  1. Add your own resource tag name (which doesn't start with aws: prefix) to the notebook instance.
  2. Skip resource tags which starts with "aws:" prefix when you copy resource tags from notebook instance.
AWS
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.