MCPcopy Create free account
hub / github.com/awsdocs/aws-doc-sdk-examples / Activity

Class Activity

python/example_code/stepfunctions/activities.py:22–157  ·  view source on GitHub ↗

Encapsulates Step Function activity actions.

Source from the content-addressed store, hash-verified

20# snippet-start:[python.example_code.sfn.Activity_full]
21# snippet-start:[python.example_code.sfn.Activity_decl]
22class Activity:
23 """Encapsulates Step Function activity actions."""
24
25 def __init__(self, stepfunctions_client):
26 """
27 :param stepfunctions_client: A Boto3 Step Functions client.
28 """
29 self.stepfunctions_client = stepfunctions_client
30
31 # snippet-end:[python.example_code.sfn.Activity_decl]
32
33 # snippet-start:[python.example_code.sfn.CreateActivity]
34 def create(self, name):
35 """
36 Create an activity.
37
38 :param name: The name of the activity to create.
39 :return: The Amazon Resource Name (ARN) of the newly created activity.
40 """
41 try:
42 response = self.stepfunctions_client.create_activity(name=name)
43 except ClientError as err:
44 logger.error(
45 "Couldn't create activity %s. Here's why: %s: %s",
46 name,
47 err.response["Error"]["Code"],
48 err.response["Error"]["Message"],
49 )
50 raise
51 else:
52 return response["activityArn"]
53
54 # snippet-end:[python.example_code.sfn.CreateActivity]
55
56 # snippet-start:[python.example_code.sfn.ListActivities]
57 def find(self, name):
58 """
59 Find an activity by name. This requires listing activities until one is found
60 with a matching name.
61
62 :param name: The name of the activity to search for.
63 :return: If found, the ARN of the activity; otherwise, None.
64 """
65 try:
66 paginator = self.stepfunctions_client.get_paginator("list_activities")
67 for page in paginator.paginate():
68 for activity in page.get("activities", []):
69 if activity["name"] == name:
70 return activity["activityArn"]
71 except ClientError as err:
72 logger.error(
73 "Couldn't list activities. Here's why: %s: %s",
74 err.response["Error"]["Code"],
75 err.response["Error"]["Message"],
76 )
77 raise
78
79 # snippet-end:[python.example_code.sfn.ListActivities]

Calls

no outgoing calls

Tested by 2

__init__Method · 0.72