in sagemaker_run_notebook/run_notebook.py [0:0]
def describe_run(job_name, session=None):
"""Describe a particular notebook run.
Args:
job_name (str): The name of the processing job that ran the notebook.
Returns:
A dictionary with keys for each element of the job description. For example::
{'Notebook': 'scala-spark-test.ipynb',
'Rule': '',
'Parameters': '{"input": "s3://notebook-testing/const.txt"}',
'Job': 'papermill-scala-spark-test-2020-10-21-20-00-11',
'Status': 'Completed',
'Failure': None,
'Created': datetime.datetime(2020, 10, 21, 13, 0, 12, 817000, tzinfo=tzlocal()),
'Start': datetime.datetime(2020, 10, 21, 13, 4, 1, 58000, tzinfo=tzlocal()),
'End': datetime.datetime(2020, 10, 21, 13, 4, 55, 710000, tzinfo=tzlocal()),
'Elapsed': datetime.timedelta(seconds=54, microseconds=652000),
'Result': 's3://sagemaker-us-west-2-1234567890/papermill_output/scala-spark-test-2020-10-21-20-00-11.ipynb',
'Input': 's3://sagemaker-us-west-2-1234567890/papermill_input/notebook-2020-10-21-20-00-08.ipynb',
'Image': 'spark-scala-notebook-runner',
'Instance': 'ml.m5.large',
'Role': 'BasicExecuteNotebookRole-us-west-2'}
"""
session = ensure_session(session)
client = session.client("sagemaker")
while True:
try:
desc = client.describe_processing_job(ProcessingJobName=job_name)
break
except botocore.exceptions.ClientError as e:
if e.response["Error"]["Code"] == "ThrottlingException":
time.sleep(1)
else:
raise e
status = desc["ProcessingJobStatus"]
if status == "Completed":
output_prefix = desc["ProcessingOutputConfig"]["Outputs"][0]["S3Output"][
"S3Uri"
]
notebook_name = os.path.basename(desc["Environment"]["PAPERMILL_OUTPUT"])
result = "{}/{}".format(output_prefix, notebook_name)
else:
result = None
if status == "Failed":
failure = desc["FailureReason"]
else:
failure = None
d = {}
d["Notebook"] = desc["Environment"].get("PAPERMILL_NOTEBOOK_NAME", "")
d["Rule"] = desc["Environment"].get("AWS_EVENTBRIDGE_RULE", "")
d["Parameters"] = desc["Environment"].get("PAPERMILL_PARAMS", "")
d["Job"] = job_name
d["Status"] = status
d["Failure"] = failure
d["Created"] = desc["CreationTime"]
d["Start"] = desc.get("ProcessingStartTime")
d["End"] = desc.get("ProcessingEndTime")
elapsed = None
if d.get("Start") is not None and d.get("End") is not None:
elapsed = d["End"] - d["Start"]
d["Elapsed"] = elapsed
d["Result"] = result
d["Input"] = desc["ProcessingInputs"][0]["S3Input"]["S3Uri"]
d["Image"] = abbreviate_image(desc["AppSpecification"]["ImageUri"])
d["Instance"] = desc["ProcessingResources"]["ClusterConfig"]["InstanceType"]
d["Role"] = abbreviate_role(desc["RoleArn"])
return d