diff --git a/doc/services.rst b/doc/services.rst index eee4e9e..c2ac225 100644 --- a/doc/services.rst +++ b/doc/services.rst @@ -20,6 +20,8 @@ This module provides classes to build steps that integrate with Amazon DynamoDB, - `Amazon SQS <#amazon-sqs>`__ +- `AWS Step Functions <#aws-step-functions>`__ + Amazon DynamoDB ---------------- @@ -82,3 +84,8 @@ Amazon SNS Amazon SQS ----------- .. autoclass:: stepfunctions.steps.service.SqsSendMessageStep + +AWS Step Functions +------------------ +.. autoclass:: stepfunctions.steps.service.StepFunctionsStartExecutionStep + diff --git a/src/stepfunctions/steps/__init__.py b/src/stepfunctions/steps/__init__.py index 93bc0d9..cb71b3b 100644 --- a/src/stepfunctions/steps/__init__.py +++ b/src/stepfunctions/steps/__init__.py @@ -34,3 +34,4 @@ from stepfunctions.steps.service import EventBridgePutEventsStep from stepfunctions.steps.service import GlueDataBrewStartJobRunStep from stepfunctions.steps.service import SnsPublishStep, SqsSendMessageStep +from stepfunctions.steps.service import StepFunctionsStartExecutionStep diff --git a/src/stepfunctions/steps/integration_resources.py b/src/stepfunctions/steps/integration_resources.py index 5223f14..46a15df 100644 --- a/src/stepfunctions/steps/integration_resources.py +++ b/src/stepfunctions/steps/integration_resources.py @@ -24,23 +24,35 @@ class IntegrationPattern(Enum): WaitForTaskToken = "waitForTaskToken" WaitForCompletion = "sync" - RequestResponse = "" + CallAndContinue = "" -def get_service_integration_arn(service, api, integration_pattern=IntegrationPattern.RequestResponse): +def get_service_integration_arn(service, api, integration_pattern=IntegrationPattern.CallAndContinue, version=None): """ ARN builder for task integration Args: service (str): The service name for the service integration api (str): The api of the service integration - integration_pattern (IntegrationPattern, optional): The integration pattern for the task. (Default: IntegrationPattern.RequestResponse) + integration_pattern (IntegrationPattern, optional): The integration pattern for the task. (Default: IntegrationPattern.CallAndContinue) + version (int, optional): The version of the resource to use. (Default: None) """ arn = "" - if integration_pattern == IntegrationPattern.RequestResponse: + if integration_pattern == IntegrationPattern.CallAndContinue: arn = f"arn:{get_aws_partition()}:states:::{service}:{api.value}" else: arn = f"arn:{get_aws_partition()}:states:::{service}:{api.value}.{integration_pattern.value}" + + if version: + arn = f"{arn}:{str(version)}" + return arn +def is_integration_pattern_valid(integration_pattern, supported_integration_patterns): + if not isinstance(integration_pattern, IntegrationPattern): + raise TypeError(f"Integration pattern must be of type {IntegrationPattern}") + elif integration_pattern not in supported_integration_patterns: + raise ValueError(f"Integration Pattern ({integration_pattern.name}) is not supported for this step - " + f"Please use one of the following: " + f"{[integ_type.name for integ_type in supported_integration_patterns]}") diff --git a/src/stepfunctions/steps/service.py b/src/stepfunctions/steps/service.py index a0c3950..986217c 100644 --- a/src/stepfunctions/steps/service.py +++ b/src/stepfunctions/steps/service.py @@ -15,7 +15,8 @@ from enum import Enum from stepfunctions.steps.states import Task from stepfunctions.steps.fields import Field -from stepfunctions.steps.integration_resources import IntegrationPattern, get_service_integration_arn +from stepfunctions.steps.integration_resources import IntegrationPattern, get_service_integration_arn,\ + is_integration_pattern_valid DYNAMODB_SERVICE_NAME = "dynamodb" EKS_SERVICES_NAME = "eks" @@ -24,6 +25,7 @@ GLUE_DATABREW_SERVICE_NAME = "databrew" SNS_SERVICE_NAME = "sns" SQS_SERVICE_NAME = "sqs" +STEP_FUNCTIONS_SERVICE_NAME = "states" class DynamoDBApi(Enum): @@ -70,6 +72,10 @@ class SqsApi(Enum): SendMessage = "sendMessage" +class StepFunctions(Enum): + StartExecution = "startExecution" + + class DynamoDBGetItemStep(Task): """ Creates a Task state to get an item from DynamoDB. See `Call DynamoDB APIs with Step Functions `_ for more details. @@ -887,3 +893,54 @@ def __init__(self, state_id, **kwargs): ElasticMapReduceApi.ModifyInstanceGroupByName) super(EmrModifyInstanceGroupByNameStep, self).__init__(state_id, **kwargs) + + +class StepFunctionsStartExecutionStep(Task): + + """ + Creates a Task state that starts an execution of a state machine. See `Manage AWS Step Functions Executions as an Integrated Service