-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathget_jobs.py
64 lines (52 loc) · 1.77 KB
/
get_jobs.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import json
import boto3
import sagemaker
from sagemaker import get_execution_role
from sagemaker.processing import ScriptProcessor
from sagemaker.workflow.steps import ProcessingStep
from sagemaker.workflow.pipeline import Pipeline
from sagemaker.workflow.pipeline_context import PipelineSession
region = "us-west-2"
role = "arn:aws:iam::316018694217:role/service-role/AmazonSageMaker-ExecutionRole-20230309T110736"
img_uri = "316018694217.dkr.ecr.us-west-2.amazonaws.com/ds-scrape:latest"
pipeline_name = "DataScienceJobScrape"
processing_instance_count = 1
instance_type = "ml.t3.medium"
print(f"region: {region}")
print(f"role: {role}")
# Define processing env based on customized Docker container in ECR
script_processor = ScriptProcessor(
command=["python3"],
image_uri= img_uri,
role=role,
instance_count=1,
instance_type= instance_type,
)
# Define Steps
step_scrape = ProcessingStep(
name="ds-scrape",
processor=script_processor,
inputs=None,
outputs=None,
code="src/scrape.py",
)
# Define pipeline
pipeline = Pipeline(
name=pipeline_name,
parameters=[processing_instance_count],
steps=[step_scrape],
)
if __name__ == "__main__":
print(f"SageMaker Pipeline Definition: \n{json.loads(pipeline.definition())}")
print("submitting sagemaker pipeline.")
pipeline.upsert(role_arn=role)
print("start sagemaker pipeline.")
execution = pipeline.start()
print(f"SageMaker Pipeline Description: {execution.describe()}")
status = execution.describe()['PipelineExecutionStatus']
if status == 'Succeeded':
print('Pipeline execution completed successfully!')
elif status == 'Failed':
print('Pipeline execution failed.')
else:
print(f'Pipeline execution is still in progress. Status: {status}')