0

Bit of an edge case ask, basically I'm trying to write a general purpose script that can be set up as a cronjob on AWS Sagemaker that will notify users if an instance is still active. If possible, I'd like to be able to call name of the AWS Sagemaker instance (different from the name of the active jupyter notebook) within the cronjob.

Haven't been able to find anything in the boto3 or sagemaker documentation specific to this. I know that the instance name is contained within the URL path, but similarly haven't found a way to reference back to this. I'm expecting this isn't an intended functionality so will probably just go ahead with setting values manually in a config file, but if anyone has any creative solutions I'd appreciate the input!

2
  • 1
    This is more of a Jupyter question. This might help: stackoverflow.com/questions/12544056/… Commented Jan 29, 2020 at 10:17
  • Thanks @JulienSimon, unfortunately that post is about the name of the active Jupyter notebook whereas I'm looking for the name of the AWS Sagemaker notebook instance it's being hosted in. I'll update my question to be a bit clearer here Commented Jan 29, 2020 at 17:53

1 Answer 1

3

Here's an example of how to get the instance name

def get_notebook_name():
    log_path = '/opt/ml/metadata/resource-metadata.json'
    with open(log_path, 'r') as logs:
        _logs = json.load(logs)
    return _logs['ResourceName']

From:

https://github.com/aws-samples/amazon-sagemaker-notebook-instance-lifecycle-config-samples/blob/62c44aa5e69f4266955476f24647b99d9b597aaf/scripts/auto-stop-idle/autostop.py#L79

Sign up to request clarification or add additional context in comments.

1 Comment

This isn't working for me. For a notebook named "garbage.ipynb" I get instance details about the image version: datascience-1-0-ml-t3-medium-fbbacbd136ea35c00e5ce9203df8.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.