Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

run_pipeline.py 2.8 KB

You have to be logged in to leave a comment. Sign In
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
  1. # Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
  2. # SPDX-License-Identifier: MIT-0
  3. """A CLI to create or update and run pipelines."""
  4. from __future__ import absolute_import
  5. import argparse
  6. import json
  7. import sys
  8. from pipelines._utils import get_pipeline_driver, convert_struct
  9. def main(): # pragma: no cover
  10. """The main harness that creates or updates and runs the pipeline.
  11. Creates or updates the pipeline and runs it.
  12. """
  13. parser = argparse.ArgumentParser(
  14. "Creates or updates and runs the pipeline for the pipeline script."
  15. )
  16. parser.add_argument(
  17. "-n",
  18. "--module-name",
  19. dest="module_name",
  20. type=str,
  21. help="The module name of the pipeline to import.",
  22. )
  23. parser.add_argument(
  24. "-kwargs",
  25. "--kwargs",
  26. dest="kwargs",
  27. default=None,
  28. help="Dict string of keyword arguments for the pipeline generation (if supported)",
  29. )
  30. parser.add_argument(
  31. "-role-arn",
  32. "--role-arn",
  33. dest="role_arn",
  34. type=str,
  35. help="The role arn for the pipeline service execution role.",
  36. )
  37. parser.add_argument(
  38. "-description",
  39. "--description",
  40. dest="description",
  41. type=str,
  42. default=None,
  43. help="The description of the pipeline.",
  44. )
  45. parser.add_argument(
  46. "-tags",
  47. "--tags",
  48. dest="tags",
  49. default=None,
  50. help="""List of dict strings of '[{"Key": "string", "Value": "string"}, ..]'""",
  51. )
  52. args = parser.parse_args()
  53. if args.module_name is None or args.role_arn is None:
  54. parser.print_help()
  55. sys.exit(2)
  56. tags = convert_struct(args.tags)
  57. try:
  58. pipeline = get_pipeline_driver(args.module_name, args.kwargs)
  59. print("###### Creating/updating a SageMaker Pipeline with the following definition:")
  60. parsed = json.loads(pipeline.definition())
  61. print(json.dumps(parsed, indent=2, sort_keys=True))
  62. upsert_response = pipeline.upsert(
  63. role_arn=args.role_arn, description=args.description, tags=tags
  64. )
  65. print("\n###### Created/Updated SageMaker Pipeline: Response received:")
  66. print(upsert_response)
  67. execution = pipeline.start()
  68. print(f"\n###### Execution started with PipelineExecutionArn: {execution.arn}")
  69. print("Waiting for the execution to finish...")
  70. description = execution.describe()
  71. print(f"\n###### Execution started with description: {description}")
  72. execution.wait()
  73. print("\n#####Execution completed. Execution step details:")
  74. print(execution.list_steps())
  75. # Todo print the status?
  76. except Exception as e: # pylint: disable=W0703
  77. print(f"Exception: {e}")
  78. sys.exit(1)
  79. if __name__ == "__main__":
  80. main()
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...