Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b773fea

Browse files
feat: add support for EventBridge service integration (#147)
Added EventBridgePutEvents step, which can be leveraged to create a task for sending a custom event to an event bus. Closes #141
1 parent 150cc22 commit b773fea

File tree

4 files changed

+130
-13
lines changed

4 files changed

+130
-13
lines changed

‎doc/services.rst

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ This module provides classes to build steps that integrate with Amazon DynamoDB,
88

99
- `Amazon DynamoDB <#amazon-dynamodb>`__
1010

11+
- `Amazon EMR <#amazon-emr>`__
12+
13+
- `Amazon EventBridge <#amazon-eventbridge>`__
14+
1115
- `Amazon SNS <#amazon-sns>`__
1216

1317
- `Amazon SQS <#amazon-sqs>`__
1418

15-
- `Amazon EMR <#amazon-emr>`__
16-
1719

1820
Amazon DynamoDB
1921
----------------
@@ -25,14 +27,6 @@ Amazon DynamoDB
2527

2628
.. autoclass:: stepfunctions.steps.service.DynamoDBUpdateItemStep
2729

28-
Amazon SNS
29-
-----------
30-
.. autoclass:: stepfunctions.steps.service.SnsPublishStep
31-
32-
Amazon SQS
33-
-----------
34-
.. autoclass:: stepfunctions.steps.service.SqsSendMessageStep
35-
3630
Amazon EMR
3731
-----------
3832
.. autoclass:: stepfunctions.steps.service.EmrCreateClusterStep
@@ -48,3 +42,15 @@ Amazon EMR
4842
.. autoclass:: stepfunctions.steps.service.EmrModifyInstanceFleetByNameStep
4943

5044
.. autoclass:: stepfunctions.steps.service.EmrModifyInstanceGroupByNameStep
45+
46+
Amazon EventBridge
47+
-----------
48+
.. autoclass:: stepfunctions.steps.service.EventBridgePutEventsStep
49+
50+
Amazon SNS
51+
-----------
52+
.. autoclass:: stepfunctions.steps.service.SnsPublishStep
53+
54+
Amazon SQS
55+
-----------
56+
.. autoclass:: stepfunctions.steps.service.SqsSendMessageStep

‎src/stepfunctions/steps/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
from stepfunctions.steps.sagemaker import TrainingStep, TransformStep, ModelStep, EndpointConfigStep, EndpointStep, TuningStep, ProcessingStep
2020
from stepfunctions.steps.compute import LambdaStep, BatchSubmitJobStep, GlueStartJobRunStep, EcsRunTaskStep
2121
from stepfunctions.steps.service import DynamoDBGetItemStep, DynamoDBPutItemStep, DynamoDBUpdateItemStep, DynamoDBDeleteItemStep
22-
from stepfunctions.steps.service import SnsPublishStep, SqsSendMessageStep
2322
from stepfunctions.steps.service import EmrCreateClusterStep, EmrTerminateClusterStep, EmrAddStepStep, EmrCancelStepStep, EmrSetClusterTerminationProtectionStep, EmrModifyInstanceFleetByNameStep, EmrModifyInstanceGroupByNameStep
24-
23+
from stepfunctions.steps.service import EventBridgePutEventsStep
24+
from stepfunctions.steps.service import SnsPublishStep, SqsSendMessageStep

‎src/stepfunctions/steps/service.py

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,11 @@
1818
from stepfunctions.steps.integration_resources import IntegrationPattern, get_service_integration_arn
1919

2020
DYNAMODB_SERVICE_NAME = "dynamodb"
21+
ELASTICMAPREDUCE_SERVICE_NAME = "elasticmapreduce"
22+
EVENTBRIDGE_SERVICE_NAME = "events"
2123
SNS_SERVICE_NAME = "sns"
2224
SQS_SERVICE_NAME = "sqs"
23-
ELASTICMAPREDUCE_SERVICE_NAME="elasticmapreduce"
25+
2426

2527

2628
class DynamoDBApi(Enum):
@@ -48,6 +50,10 @@ class ElasticMapReduceApi(Enum):
4850
ModifyInstanceGroupByName = "modifyInstanceGroupByName"
4951

5052

53+
class EventBridgeApi(Enum):
54+
PutEvents = "putEvents"
55+
56+
5157
class DynamoDBGetItemStep(Task):
5258
"""
5359
Creates a Task state to get an item from DynamoDB. See `Call DynamoDB APIs with Step Functions <https://docs.aws.amazon.com/step-functions/latest/dg/connect-ddb.html>`_ for more details.
@@ -77,6 +83,46 @@ def __init__(self, state_id, **kwargs):
7783
super(DynamoDBGetItemStep, self).__init__(state_id, **kwargs)
7884

7985

86+
class EventBridgePutEventsStep(Task):
87+
88+
"""
89+
Creates a Task to send custom events to Amazon EventBridge. See`Call EventBridge with Step Functions <https://docs.aws.amazon.com/step-functions/latest/dg/connect-eventbridge.html>`_ for more details.
90+
"""
91+
92+
def __init__(self, state_id, wait_for_callback=False, **kwargs):
93+
"""
94+
Args:
95+
state_id (str): State name whose length **must be** less than or equal to 128 unicode characters. State names **must be** unique within the scope of the whole state machine.
96+
comment (str, optional): Human-readable comment or description. (default: None)
97+
timeout_seconds (int, optional): Positive integer specifying timeout for the state in seconds. If the state runs longer than the specified timeout, then the interpreter fails the state with a `States.Timeout` Error Name. (default: 60)
98+
timeout_seconds_path (str, optional): Path specifying the state's timeout value in seconds from the state input. When resolved, the path must select a field whose value is a positive integer.
99+
heartbeat_seconds (int, optional): Positive integer specifying heartbeat timeout for the state in seconds. This value should be lower than the one specified for `timeout_seconds`. If more time than the specified heartbeat elapses between heartbeats from the task, then the interpreter fails the state with a `States.Timeout` Error Name.
100+
heartbeat_seconds_path (str, optional): Path specifying the state's heartbeat value in seconds from the state input. When resolved, the path must select a field whose value is a positive integer.
101+
input_path (str, optional): Path applied to the state’s raw input to select some or all of it; that selection is used by the state. (default: '$')
102+
parameters (dict, optional): The value of this field becomes the effective input for the state.
103+
result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$')
104+
output_path (str, optional): Path applied to the state’s output after the application of `result_path`, producing the effective output which serves as the raw input for the next state. (default: '$')
105+
"""
106+
107+
if wait_for_callback:
108+
"""
109+
Example resource arn: arn:aws:states:::events:putEvents.waitForTaskToken
110+
"""
111+
112+
kwargs[Field.Resource.value] = get_service_integration_arn(EVENTBRIDGE_SERVICE_NAME,
113+
EventBridgeApi.PutEvents,
114+
IntegrationPattern.WaitForTaskToken)
115+
else:
116+
"""
117+
Example resource arn: arn:aws:states:::events:putEvents
118+
"""
119+
120+
kwargs[Field.Resource.value] = get_service_integration_arn(EVENTBRIDGE_SERVICE_NAME,
121+
EventBridgeApi.PutEvents)
122+
123+
super(EventBridgePutEventsStep, self).__init__(state_id, **kwargs)
124+
125+
80126
class DynamoDBPutItemStep(Task):
81127

82128
"""

‎tests/unit/test_service_steps.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from stepfunctions.steps.service import DynamoDBGetItemStep, DynamoDBPutItemStep, DynamoDBUpdateItemStep, DynamoDBDeleteItemStep
2020
from stepfunctions.steps.service import SnsPublishStep, SqsSendMessageStep
2121
from stepfunctions.steps.service import EmrCreateClusterStep, EmrTerminateClusterStep, EmrAddStepStep, EmrCancelStepStep, EmrSetClusterTerminationProtectionStep, EmrModifyInstanceFleetByNameStep, EmrModifyInstanceGroupByNameStep
22+
from stepfunctions.steps.service import EventBridgePutEventsStep
2223

2324

2425
@patch.object(boto3.session.Session, 'region_name', 'us-east-1')
@@ -98,6 +99,70 @@ def test_sqs_send_message_step_creation():
9899
'End': True
99100
}
100101

102+
@patch.object(boto3.session.Session, 'region_name', 'us-east-1')
103+
def test_eventbridge_put_events_step_creation():
104+
step = EventBridgePutEventsStep('Send to EventBridge', parameters={
105+
"Entries": [
106+
{
107+
"Detail": {
108+
"Message": "MyMessage"
109+
},
110+
"DetailType": "MyDetailType",
111+
"EventBusName": "MyEventBus",
112+
"Source": "my.source"
113+
}
114+
]
115+
})
116+
117+
assert step.to_dict() == {
118+
"Type": "Task",
119+
"Resource": 'arn:aws:states:::events:putEvents',
120+
"Parameters": {
121+
"Entries": [
122+
{
123+
"Detail": {
124+
"Message": "MyMessage"
125+
},
126+
"DetailType": "MyDetailType",
127+
"EventBusName": "MyEventBus",
128+
"Source": "my.source"
129+
}
130+
]
131+
},
132+
"End": True
133+
}
134+
135+
step = EventBridgePutEventsStep('Send to EventBridge', wait_for_callback=True, parameters={
136+
"Entries": [
137+
{
138+
"Detail": {
139+
"Message.$": "$.MyMessage"
140+
},
141+
"DetailType": "MyDetailType",
142+
"EventBusName": "MyEventBus",
143+
"Source": "my.source"
144+
}
145+
]
146+
})
147+
148+
assert step.to_dict() == {
149+
"Type": "Task",
150+
"Resource": "arn:aws:states:::events:putEvents.waitForTaskToken",
151+
"Parameters": {
152+
"Entries": [
153+
{
154+
"Detail": {
155+
"Message.$": "$.MyMessage"
156+
},
157+
"DetailType": "MyDetailType",
158+
"EventBusName": "MyEventBus",
159+
"Source": "my.source"
160+
}
161+
]
162+
},
163+
"End": True
164+
}
165+
101166

102167
@patch.object(boto3.session.Session, 'region_name', 'us-east-1')
103168
def test_dynamodb_get_item_step_creation():

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /