diff --git a/doc/services.rst b/doc/services.rst index 76b09a0..eee4e9e 100644 --- a/doc/services.rst +++ b/doc/services.rst @@ -8,6 +8,8 @@ This module provides classes to build steps that integrate with Amazon DynamoDB, - `Amazon DynamoDB <#amazon-dynamodb>`__ +- `Amazon EKS <#amazon-eks>`__ + - `Amazon EMR <#amazon-emr>`__ - `Amazon EventBridge <#amazon-eventbridge>`__ @@ -29,6 +31,26 @@ Amazon DynamoDB .. autoclass:: stepfunctions.steps.service.DynamoDBUpdateItemStep + +Amazon EKS +---------- +.. autoclass:: stepfunctions.steps.service.EksCallStep + +.. autoclass:: stepfunctions.steps.service.EksCreateClusterStep + +.. autoclass:: stepfunctions.steps.service.EksCreateFargateProfileStep + +.. autoclass:: stepfunctions.steps.service.EksCreateNodeGroupStep + +.. autoclass:: stepfunctions.steps.service.EksDeleteClusterStep + +.. autoclass:: stepfunctions.steps.service.EksDeleteFargateProfileStep + +.. autoclass:: stepfunctions.steps.service.EksDeleteNodegroupStep + +.. autoclass:: stepfunctions.steps.service.EksRunJobStep + + Amazon EMR ----------- .. autoclass:: stepfunctions.steps.service.EmrCreateClusterStep diff --git a/src/stepfunctions/steps/__init__.py b/src/stepfunctions/steps/__init__.py index 4e85666..93bc0d9 100644 --- a/src/stepfunctions/steps/__init__.py +++ b/src/stepfunctions/steps/__init__.py @@ -19,6 +19,17 @@ from stepfunctions.steps.sagemaker import TrainingStep, TransformStep, ModelStep, EndpointConfigStep, EndpointStep, TuningStep, ProcessingStep from stepfunctions.steps.compute import LambdaStep, BatchSubmitJobStep, GlueStartJobRunStep, EcsRunTaskStep from stepfunctions.steps.service import DynamoDBGetItemStep, DynamoDBPutItemStep, DynamoDBUpdateItemStep, DynamoDBDeleteItemStep + +from stepfunctions.steps.service import ( + EksCallStep, + EksCreateClusterStep, + EksCreateFargateProfileStep, + EksCreateNodeGroupStep, + EksDeleteClusterStep, + EksDeleteFargateProfileStep, + EksDeleteNodegroupStep, + EksRunJobStep, +) from stepfunctions.steps.service import EmrCreateClusterStep, EmrTerminateClusterStep, EmrAddStepStep, EmrCancelStepStep, EmrSetClusterTerminationProtectionStep, EmrModifyInstanceFleetByNameStep, EmrModifyInstanceGroupByNameStep from stepfunctions.steps.service import EventBridgePutEventsStep from stepfunctions.steps.service import GlueDataBrewStartJobRunStep diff --git a/src/stepfunctions/steps/service.py b/src/stepfunctions/steps/service.py index 4f4a538..a0c3950 100644 --- a/src/stepfunctions/steps/service.py +++ b/src/stepfunctions/steps/service.py @@ -18,6 +18,7 @@ from stepfunctions.steps.integration_resources import IntegrationPattern, get_service_integration_arn DYNAMODB_SERVICE_NAME = "dynamodb" +EKS_SERVICES_NAME = "eks" ELASTICMAPREDUCE_SERVICE_NAME = "elasticmapreduce" EVENTBRIDGE_SERVICE_NAME = "events" GLUE_DATABREW_SERVICE_NAME = "databrew" @@ -25,7 +26,6 @@ SQS_SERVICE_NAME = "sqs" - class DynamoDBApi(Enum): GetItem = "getItem" PutItem = "putItem" @@ -33,6 +33,17 @@ class DynamoDBApi(Enum): UpdateItem = "updateItem" +class EksApi(Enum): + CreateCluster = "createCluster" + DeleteCluster = "deleteCluster" + CreateFargateProfile = "createFargateProfile" + DeleteFargateProfile = "deleteFargateProfile" + CreateNodegroup = "createNodegroup" + DeleteNodegroup = "deleteNodegroup" + RunJob = "runJob" + Call = "call" + + class ElasticMapReduceApi(Enum): CreateCluster = "createCluster" TerminateCluster = "terminateCluster" @@ -218,6 +229,309 @@ def __init__(self, state_id, **kwargs): super(DynamoDBUpdateItemStep, self).__init__(state_id, **kwargs) +class EksCreateClusterStep(Task): + """ + Creates a Task state that creates an Amazon EKS cluster. See `Call Amazon EKS with Step Functions `_ for more details. + """ + + def __init__(self, state_id, wait_for_completion=True, **kwargs): + """ + Args: + 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. + comment (str, optional): Human-readable comment or description. (default: None) + 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) + 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. + 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. + 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. + 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: '$') + parameters (dict, optional): The value of this field becomes the effective input for the state. + result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') + 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: '$') + wait_for_completion (bool, optional): Boolean value set to `True` if the Task state should wait to complete before proceeding to the next step in the workflow. (default: True) + """ + if wait_for_completion: + """ + Example resource arn: arn:aws:states:::eks:createCluster.sync + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.CreateCluster, + IntegrationPattern.WaitForCompletion) + else: + """ + Example resource arn: arn:aws:states:::eks:createCluster + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.CreateCluster) + + super(EksCreateClusterStep, self).__init__(state_id, **kwargs) + + +class EksCreateFargateProfileStep(Task): + """ + Creates a Task state that creates an AWS Fargate profile for your Amazon EKS cluster. See `Call Amazon EKS with Step Functions `_ for more details. + """ + + def __init__(self, state_id, wait_for_completion=True, **kwargs): + """ + Args: + 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. + comment (str, optional): Human-readable comment or description. (default: None) + 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) + 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. + 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. + 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. + 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: '$') + parameters (dict, optional): The value of this field becomes the effective input for the state. + result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') + 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: '$') + wait_for_completion (bool, optional): Boolean value set to `True` if the Task state should wait to complete before proceeding to the next step in the workflow. (default: True) + """ + if wait_for_completion: + """ + Example resource arn: arn:aws:states:::eks:createFargateProfile.sync + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.CreateFargateProfile, + IntegrationPattern.WaitForCompletion) + else: + """ + Example resource arn: arn:aws:states:::eks:createFargateProfile + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.CreateFargateProfile) + + super(EksCreateFargateProfileStep, self).__init__(state_id, **kwargs) + + +class EksDeleteFargateProfileStep(Task): + """ + Creates a Task state that deletes an AWS Fargate profile. See `Call Amazon EKS with Step Functions `_ for more details. + """ + + def __init__(self, state_id, wait_for_completion=True, **kwargs): + """ + Args: + 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. + comment (str, optional): Human-readable comment or description. (default: None) + 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) + 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. + 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. + 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. + 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: '$') + parameters (dict, optional): The value of this field becomes the effective input for the state. + result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') + 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: '$') + wait_for_completion (bool, optional): Boolean value set to `True` if the Task state should wait to complete before proceeding to the next step in the workflow. (default: True) + """ + if wait_for_completion: + """ + Example resource arn: arn:aws:states:::eks:deleteFargateProfile.sync + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.DeleteFargateProfile, + IntegrationPattern.WaitForCompletion) + else: + """ + Example resource arn: arn:aws:states:::eks:deleteFargateProfile + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.DeleteFargateProfile) + + super(EksDeleteFargateProfileStep, self).__init__(state_id, **kwargs) + + +class EksCreateNodeGroupStep(Task): + """ + Creates a Task state that creates a node group for an Amazon EKS cluster. See `Call Amazon EKS with Step Functions `_ for more details. + """ + + def __init__(self, state_id, wait_for_completion=True, **kwargs): + """ + Args: + 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. + comment (str, optional): Human-readable comment or description. (default: None) + 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) + 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. + 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. + 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. + 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: '$') + parameters (dict, optional): The value of this field becomes the effective input for the state. + result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') + 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: '$') + wait_for_completion (bool, optional): Boolean value set to `True` if the Task state should wait to complete before proceeding to the next step in the workflow. (default: True) + """ + if wait_for_completion: + """ + Example resource arn: arn:aws:states:::eks:createNodegroup.sync + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.CreateNodegroup, + IntegrationPattern.WaitForCompletion) + else: + """ + Example resource arn: arn:aws:states:::eks:createNodegroup + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.CreateNodegroup) + + super(EksCreateNodeGroupStep, self).__init__(state_id, **kwargs) + + +class EksDeleteNodegroupStep(Task): + """ + Creates a Task state that deletes an Amazon EKS node group for a cluster. See `Call Amazon EKS with Step Functions `_ for more details. + """ + + def __init__(self, state_id, wait_for_completion=True, **kwargs): + """ + Args: + 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. + comment (str, optional): Human-readable comment or description. (default: None) + 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) + 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. + 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. + 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. + 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: '$') + parameters (dict, optional): The value of this field becomes the effective input for the state. + result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') + 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: '$') + wait_for_completion (bool, optional): Boolean value set to `True` if the Task state should wait to complete before proceeding to the next step in the workflow. (default: True) + """ + if wait_for_completion: + """ + Example resource arn: arn:aws:states:::eks:deleteNodegroup.sync + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.DeleteNodegroup, + IntegrationPattern.WaitForCompletion) + else: + """ + Example resource arn: arn:aws:states:::eks:deleteNodegroup + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.DeleteNodegroup) + + super(EksDeleteNodegroupStep, self).__init__(state_id, **kwargs) + + +class EksDeleteClusterStep(Task): + """ + Creates a Task state that deletes an Amazon EKS cluster. See `Call Amazon EKS with Step Functions `_ for more details. + """ + + def __init__(self, state_id, wait_for_completion=True, **kwargs): + """ + Args: + 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. + comment (str, optional): Human-readable comment or description. (default: None) + 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) + 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. + 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. + 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. + 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: '$') + parameters (dict, optional): The value of this field becomes the effective input for the state. + result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') + 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: '$') + wait_for_completion (bool, optional): Boolean value set to `True` if the Task state should wait to complete before proceeding to the next step in the workflow. (default: True) + """ + if wait_for_completion: + """ + Example resource arn: arn:aws:states:::eks:deleteCluster.sync + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.DeleteCluster, + IntegrationPattern.WaitForCompletion) + else: + """ + Example resource arn: arn:aws:states:::eks:deleteCluster + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.DeleteCluster) + + super(EksDeleteClusterStep, self).__init__(state_id, **kwargs) + + +class EksRunJobStep(Task): + """ + Creates a Task state that allows you to run a job on your Amazon EKS cluster. See `Call Amazon EKS with Step Functions `_ for more details. + """ + + def __init__(self, state_id, wait_for_completion=True, **kwargs): + """ + Args: + 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. + comment (str, optional): Human-readable comment or description. (default: None) + 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) + 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. + 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. + 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. + 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: '$') + parameters (dict, optional): The value of this field becomes the effective input for the state. + result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') + 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: '$') + wait_for_completion (bool, optional): Boolean value set to `True` if the Task state should wait to complete before proceeding to the next step in the workflow. (default: True) + """ + if wait_for_completion: + """ + Example resource arn: arn:aws:states:::eks:runJob.sync + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.RunJob, + IntegrationPattern.WaitForCompletion) + else: + """ + Example resource arn: arn:aws:states:::eks:runJob + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.RunJob) + + super(EksRunJobStep, self).__init__(state_id, **kwargs) + + +class EksCallStep(Task): + """ + Creates a Task state that allows you to use the Kubernetes API to read and write Kubernetes resource objects via a Kubernetes API endpoint. See `Call Amazon EKS with Step Functions `_ for more details. + """ + + def __init__(self, state_id, **kwargs): + """ + Args: + 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. + comment (str, optional): Human-readable comment or description. (default: None) + 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) + 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. + 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. + 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. + 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: '$') + parameters (dict, optional): The value of this field becomes the effective input for the state. + result_path (str, optional): Path specifying the raw input’s combination with or replacement by the state’s result. (default: '$') + 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: '$') + """ + + """ + Example resource arn: arn:aws:states:::eks:call + """ + + kwargs[Field.Resource.value] = get_service_integration_arn(EKS_SERVICES_NAME, + EksApi.Call) + + super(EksCallStep, self).__init__(state_id, **kwargs) + + class GlueDataBrewStartJobRunStep(Task): """ diff --git a/tests/unit/test_service_steps.py b/tests/unit/test_service_steps.py index 627ae55..25861ec 100644 --- a/tests/unit/test_service_steps.py +++ b/tests/unit/test_service_steps.py @@ -12,11 +12,20 @@ # permissions and limitations under the License. from __future__ import absolute_import -import pytest import boto3 from unittest.mock import patch from stepfunctions.steps.service import DynamoDBGetItemStep, DynamoDBPutItemStep, DynamoDBUpdateItemStep, DynamoDBDeleteItemStep +from stepfunctions.steps.service import ( + EksCallStep, + EksCreateClusterStep, + EksCreateFargateProfileStep, + EksCreateNodeGroupStep, + EksDeleteClusterStep, + EksDeleteFargateProfileStep, + EksDeleteNodegroupStep, + EksRunJobStep, +) from stepfunctions.steps.service import EmrCreateClusterStep, EmrTerminateClusterStep, EmrAddStepStep, EmrCancelStepStep, EmrSetClusterTerminationProtectionStep, EmrModifyInstanceFleetByNameStep, EmrModifyInstanceGroupByNameStep from stepfunctions.steps.service import EventBridgePutEventsStep from stepfunctions.steps.service import SnsPublishStep, SqsSendMessageStep @@ -693,3 +702,459 @@ def test_databrew_start_job_run_step_creation(): }, 'End': True } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_create_cluster_step_creation(): + step = EksCreateClusterStep("Create Eks cluster", wait_for_completion=False, parameters={ + 'Name': 'MyCluster', + 'ResourcesVpcConfig': { + 'SubnetIds': [ + 'subnet-00000000000000000', + 'subnet-00000000000000001' + ] + }, + 'RoleArn': 'arn:aws:iam::123456789012:role/MyEKSClusterRole' + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:createCluster', + 'Parameters': { + 'Name': 'MyCluster', + 'ResourcesVpcConfig': { + 'SubnetIds': [ + 'subnet-00000000000000000', + 'subnet-00000000000000001' + ] + }, + 'RoleArn': 'arn:aws:iam::123456789012:role/MyEKSClusterRole' + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_create_cluster_step_creation_sync(): + step = EksCreateClusterStep("Create Eks cluster sync", parameters={ + 'Name': 'MyCluster', + 'ResourcesVpcConfig': { + 'SubnetIds': [ + 'subnet-00000000000000000', + 'subnet-00000000000000001' + ] + }, + 'RoleArn': 'arn:aws:iam::123456789012:role/MyEKSClusterRole' + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:createCluster.sync', + 'Parameters': { + 'Name': 'MyCluster', + 'ResourcesVpcConfig': { + 'SubnetIds': [ + 'subnet-00000000000000000', + 'subnet-00000000000000001' + ] + }, + 'RoleArn': 'arn:aws:iam::123456789012:role/MyEKSClusterRole' + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_delete_cluster_step_creation(): + step = EksDeleteClusterStep("Delete Eks cluster", wait_for_completion=False, parameters={ + 'Name': 'MyCluster' + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:deleteCluster', + 'Parameters': { + 'Name': 'MyCluster' + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_delete_cluster_step_creation_sync(): + step = EksDeleteClusterStep("Delete Eks cluster sync", parameters={ + 'Name': 'MyCluster' + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:deleteCluster.sync', + 'Parameters': { + 'Name': 'MyCluster' + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_create_fargate_profile_step_creation(): + step = EksCreateFargateProfileStep("Create Fargate profile", wait_for_completion=False, parameters={ + 'ClusterName': 'MyCluster', + 'FargateProfileName': 'MyFargateProfile', + 'PodExecutionRoleArn': 'arn:aws:iam::123456789012:role/MyFargatePodExecutionRole', + 'Selectors': [{ + 'Namespace': 'my-namespace', + 'Labels': {'my-label': 'my-value'} + }] + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:createFargateProfile', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'FargateProfileName': 'MyFargateProfile', + 'PodExecutionRoleArn': 'arn:aws:iam::123456789012:role/MyFargatePodExecutionRole', + 'Selectors': [{ + 'Namespace': 'my-namespace', + 'Labels': {'my-label': 'my-value'} + }] + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_create_fargate_profile_step_creation_sync(): + step = EksCreateFargateProfileStep("Create Fargate profile sync", parameters={ + 'ClusterName': 'MyCluster', + 'FargateProfileName': 'MyFargateProfile', + 'PodExecutionRoleArn': 'arn:aws:iam::123456789012:role/MyFargatePodExecutionRole', + 'Selectors': [{ + 'Namespace': 'my-namespace', + 'Labels': {'my-label': 'my-value'} + }] + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:createFargateProfile.sync', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'FargateProfileName': 'MyFargateProfile', + 'PodExecutionRoleArn': 'arn:aws:iam::123456789012:role/MyFargatePodExecutionRole', + 'Selectors': [{ + 'Namespace': 'my-namespace', + 'Labels': {'my-label': 'my-value'} + }] + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_delete_fargate_profile_step_creation(): + step = EksDeleteFargateProfileStep("Delete Fargate profile", wait_for_completion=False, parameters={ + 'ClusterName': 'MyCluster', + 'FargateProfileName': 'MyFargateProfile' + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:deleteFargateProfile', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'FargateProfileName': 'MyFargateProfile' + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_delete_fargate_profile_step_creation_sync(): + step = EksDeleteFargateProfileStep("Delete Fargate profile sync", parameters={ + 'ClusterName': 'MyCluster', + 'FargateProfileName': 'MyFargateProfile' + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:deleteFargateProfile.sync', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'FargateProfileName': 'MyFargateProfile' + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_create_node_group_step_creation(): + step = EksCreateNodeGroupStep("Create Node Group", wait_for_completion=False, parameters={ + 'ClusterName': 'MyCluster', + 'NodegroupName': 'MyNodegroup', + 'NodeRole': 'arn:aws:iam::123456789012:role/MyNodeInstanceRole', + 'Subnets': [ + 'subnet-00000000000000000', + 'subnet-00000000000000001' + ] + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:createNodegroup', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'NodegroupName': 'MyNodegroup', + 'NodeRole': 'arn:aws:iam::123456789012:role/MyNodeInstanceRole', + 'Subnets': [ + 'subnet-00000000000000000', + 'subnet-00000000000000001' + ], + }, + 'End': True + } + + +def test_eks_create_node_group_step_creation_sync(): + step = EksCreateNodeGroupStep("Create Node Group sync", parameters={ + 'ClusterName': 'MyCluster', + 'NodegroupName': 'MyNodegroup', + 'NodeRole': 'arn:aws:iam::123456789012:role/MyNodeInstanceRole', + 'Subnets': [ + 'subnet-00000000000000000', + 'subnet-00000000000000001' + ] + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:createNodegroup.sync', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'NodegroupName': 'MyNodegroup', + 'NodeRole': 'arn:aws:iam::123456789012:role/MyNodeInstanceRole', + 'Subnets': [ + 'subnet-00000000000000000', + 'subnet-00000000000000001' + ], + }, + 'End': True + } + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_delete_node_group_step_creation(): + step = EksDeleteNodegroupStep("Delete Node Group", wait_for_completion=False, parameters={ + 'ClusterName': 'MyCluster', + 'NodegroupName': 'MyNodegroup' + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:deleteNodegroup', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'NodegroupName': 'MyNodegroup' + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_delete_node_group_step_creation_sync(): + step = EksDeleteNodegroupStep("Delete Node Group sync", parameters={ + 'ClusterName': 'MyCluster', + 'NodegroupName': 'MyNodegroup' + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:deleteNodegroup.sync', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'NodegroupName': 'MyNodegroup' + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_run_job_step_creation(): + step = EksRunJobStep("Run Job", wait_for_completion=False, parameters={ + 'ClusterName': 'MyCluster', + 'CertificateAuthority': 'ANPAJ2UCCR6DPCEXAMPLE', + 'Endpoint': 'https://AKIAIOSFODNN7EXAMPLE.yl4.us-east-1.eks.amazonaws.com', + 'Job': { + 'apiVersion': 'batch/v1', + 'kind': 'Job', + 'metadata': { + 'name': 'example-job' + }, + 'spec': { + 'backoffLimit': 0, + 'template': { + 'metadata': { + 'name': 'example-job' + }, + 'spec': { + 'containers': [ + { + 'name': 'pi-2000', + 'image': 'perl', + 'command': ['perl'], + 'args': [ + '-Mbignum=bpi', + '-wle', + 'print bpi(2000)' + ] + } + ], + 'restartPolicy': 'Never' + } + } + } + } + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:runJob', + 'Parameters': { + 'CertificateAuthority': 'ANPAJ2UCCR6DPCEXAMPLE', + 'ClusterName': 'MyCluster', + 'Endpoint': 'https://AKIAIOSFODNN7EXAMPLE.yl4.us-east-1.eks.amazonaws.com', + 'Job': { + 'apiVersion': 'batch/v1', + 'kind': 'Job', + 'metadata': {'name': 'example-job'}, + 'spec': { + 'backoffLimit': 0, + 'template': { + 'metadata': {'name': 'example-job'}, + 'spec': { + 'containers': [{ + 'args': ['-Mbignum=bpi', + '-wle', + 'print ' + 'bpi(2000)'], + 'command': ['perl'], + 'image': 'perl', + 'name': 'pi-2000'}], + 'restartPolicy': 'Never'} + } + } + } + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_run_job_step_creation_sync(): + step = EksRunJobStep("Run Job sync", parameters={ + 'ClusterName': 'MyCluster', + 'CertificateAuthority': 'ANPAJ2UCCR6DPCEXAMPLE', + 'Endpoint': 'https://AKIAIOSFODNN7EXAMPLE.yl4.us-east-1.eks.amazonaws.com', + 'LogOptions': { + 'RetrieveLogs': True + }, + 'Job': { + 'apiVersion': 'batch/v1', + 'kind': 'Job', + 'metadata': { + 'name': 'example-job' + }, + 'spec': { + 'backoffLimit': 0, + 'template': { + 'metadata': { + 'name': 'example-job' + }, + 'spec': { + 'containers': [ + { + 'name': 'pi-2000', + 'image': 'perl', + 'command': ['perl'], + 'args': [ + '-Mbignum=bpi', + '-wle', + 'print bpi(2000)' + ] + } + ], + 'restartPolicy': 'Never' + } + } + } + } + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:runJob.sync', + 'Parameters': { + 'CertificateAuthority': 'ANPAJ2UCCR6DPCEXAMPLE', + 'ClusterName': 'MyCluster', + 'Endpoint': 'https://AKIAIOSFODNN7EXAMPLE.yl4.us-east-1.eks.amazonaws.com', + 'LogOptions': { + 'RetrieveLogs': True + }, + 'Job': { + 'apiVersion': 'batch/v1', + 'kind': 'Job', + 'metadata': {'name': 'example-job'}, + 'spec': { + 'backoffLimit': 0, + 'template': { + 'metadata': {'name': 'example-job'}, + 'spec': { + 'containers': [{ + 'args': ['-Mbignum=bpi', + '-wle', + 'print ' + 'bpi(2000)'], + 'command': ['perl'], + 'image': 'perl', + 'name': 'pi-2000'}], + 'restartPolicy': 'Never'} + } + } + } + }, + 'End': True + } + + +@patch.object(boto3.session.Session, 'region_name', 'us-east-1') +def test_eks_call_step_creation(): + step = EksCallStep("Call", parameters={ + 'ClusterName': 'MyCluster', + 'CertificateAuthority': 'ANPAJ2UCCR6DPCEXAMPLE', + 'Endpoint': 'https://444455556666.yl4.us-east-1.eks.amazonaws.com', + 'Method': 'GET', + 'Path': '/api/v1/namespaces/default/pods', + 'QueryParameters': { + 'labelSelector': [ + 'job-name=example-job' + ] + } + }) + + assert step.to_dict() == { + 'Type': 'Task', + 'Resource': 'arn:aws:states:::eks:call', + 'Parameters': { + 'ClusterName': 'MyCluster', + 'CertificateAuthority': 'ANPAJ2UCCR6DPCEXAMPLE', + 'Endpoint': 'https://444455556666.yl4.us-east-1.eks.amazonaws.com', + 'Method': 'GET', + 'Path': '/api/v1/namespaces/default/pods', + 'QueryParameters': { + 'labelSelector': [ + 'job-name=example-job' + ] + } + }, + 'End': True + }