forked from aws/amazon-sagemaker-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_autopilot_job_status.py
37 lines (34 loc) · 1.32 KB
/
check_autopilot_job_status.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import boto3
import json
import logging
sagemaker_client = boto3.client("sagemaker")
def lambda_handler(event, context):
try:
payload = json.loads(event["Records"][0]["body"])
callback_token = payload["token"]
autopilot_job = sagemaker_client.describe_auto_ml_job(
AutoMLJobName=payload["arguments"]["AutopilotJobName"]
)
autopilot_job_status = autopilot_job["AutoMLJobStatus"]
if autopilot_job_status == "Completed":
sagemaker_client.send_pipeline_execution_step_success(
CallbackToken=callback_token
)
elif autopilot_job_status in ["InProgress", "Stopping"]:
raise ValueError("Autopilot training not finished yet. Retrying later...")
else:
sagemaker_client.send_pipeline_execution_step_failure(
CallbackToken=callback_token,
FailureReason=autopilot_job.get(
"FailureReason",
f"Autopilot training job (status: {autopilot_job_status}) failed to finish.",
),
)
except ValueError:
raise
except Exception as e:
logging.exception(e)
sagemaker_client.send_pipeline_execution_step_failure(
CallbackToken=callback_token,
FailureReason=str(e),
)