aws / aws-step-functions-data-science-sdk-python

Step Functions Data Science SDK for building machine learning (ML) workflows and pipelines on AWS
Apache License 2.0
285 stars 87 forks source link

refactor: Updated EKS integration to use integration_pattern #177

Closed ca-nguyen closed 2 years ago

ca-nguyen commented 2 years ago

Description

Update Amazon EKS service integration to use integration_pattern input instead or wait_for_completion flag.

Fixes #(issue) - N/A

Why is the change necessary?

This change is necessary for consistency with the new service integration implementation pattern introduced in commit (Add support for Nested Step Functions) that uses the integration_pattern arg in the step constructor to build the resource.

Support for Amazon EKS service integration was added in this commit, but not released yet. A later commit (Add support for Nested Step Functions) introduced a new implementation pattern using the IntegrationPattern enum as input to construct the step instead of the wait_for_completion flag. (See PR for more detail on rationale behind the implementation).

Solution

Replace the wait_for_completion flag with integration_pattern arg for the step construction:

The IntegrationPattern is used to build the Resource arn as follow: IntegrationPattern Resource Doc
WaitForCompletion "arn:aws:states:::states:eks:createCluster.sync" Run A job
CallAndContinue "arn:aws:states:::states:eks:createCluster" Request Response

See Service Integration Patterns for more details

Apply changes to the following steps:

Normally, replacing a constructor argument would be a breaking change, but since we have not released support for Amazon EKS service integration yet, it is acceptable to do so. After next release, it making such changes will be considered as not being backward compatible.

Testing

create_node_group_step = EksCreateNodegroupStep( "Create Node Group", integration_pattern=IntegrationPattern.WaitForCompletion, parameters={ 'ClusterName': 'ExampleCluster', 'NodegroupName': 'ExampleNodegroup', 'NodeRole': , 'Subnets': [ 'subnet-XXXXXXXXXXXXXXXXX', 'subnet-XXXXXXXXXXXXXXXXX' ] }, result_path="$.nodegroup" )

run_job_step = EksRunJobStep("Run Job", integration_pattern=IntegrationPattern.WaitForCompletion, parameters={ 'ClusterName': 'ExampleCluster', 'CertificateAuthority.$': '$.eks.Cluster.CertificateAuthority.Data', 'Endpoint.$': '$.eks.Cluster.Endpoint', '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-20', 'image': 'perl', 'command': ['perl'], 'args': [ '-Mbignum=bpi', '-wle', 'print bpi(20)' ] } ], 'restartPolicy': 'Never' } } } } }, result_path="$.RunJobResult" )

call_delete_job_step = EksCallStep("Call", parameters={ 'ClusterName': 'ExampleCluster', 'CertificateAuthority.$': '$.eks.Cluster.CertificateAuthority.Data', 'Endpoint.$': '$.eks.Cluster.Endpoint', 'Method': 'DELETE', 'Path': '/apis/batch/v1/namespaces/default/jobs/example-job',

})

delete_node_group = EksDeleteNodegroupStep( "Delete Node Group", integration_pattern=IntegrationPattern.WaitForCompletion, parameters={ 'ClusterName': 'ExampleCluster', 'NodegroupName': 'ExampleNodegroup' })

delete_cluster_step = EksDeleteClusterStep( "Delete Eks cluster", integration_pattern=IntegrationPattern.WaitForCompletion, parameters={ 'Name': 'ExampleCluster' })

Chain the steps

path=Chain([create_cluster_step, create_node_group_step, run_job_step, call_delete_job_step, delete_node_group, delete_cluster_step])

Define workflow

workflow = Workflow( name="EKSStateMachineExample", definition=path, role= )

workflow.create() workflow.execute()

##### Fargate profile creation/deletion test
Using an existing cluster <cluster_name>, create Fargate profile and delete it once profile creation succeeds

create_fargate_profile_step = EksCreateFargateProfileStep( "Create Fargate profile", integration_pattern=IntegrationPattern.WaitForCompletion, parameters={ 'ClusterName': , 'FargateProfileName': 'ExampleFargateProfile', 'PodExecutionRoleArn': , 'Selectors': [{ 'Namespace': 'my-namespace', 'Labels': {'my-label': 'my-value'} }], 'Subnets': [ 'subnet-XXXXXXXX' ] } )

delete_fargate_profile_step = EksDeleteFargateProfileStep( "Delete Fargate profile", integration_pattern=IntegrationPattern.CallAndContinue, parameters={ 'ClusterName': , 'FargateProfileName': 'ExampleFargateProfile' } )

Chain the steps

path=Chain([create_fargate_profile_step, delete_fargate_profile_step])

Define the workflow

workflow = Workflow( name="EKSFargateProfileExample", definition=path, role= )

workflow.create() workflow.execute()



----

### Pull Request Checklist

Please check all boxes (including N/A items)

#### Testing

- [X] Unit tests added
- [X] Integration test added - **N/A** No integ tests added since external resources required for testing
- [X] Manual testing - No integ tests added since external resources required for testing

#### Documentation

- [X] __docs__: All relevant [docs](https://github.com/aws/aws-step-functions-data-science-sdk-python/tree/main/doc) updated
- [X] __docstrings__: All public APIs documented

### Title and description

- [X] __Change type__: Title is prefixed with change type: and follows [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/)
- [X] __References__: Indicate issues fixed via: `Fixes #xxx` - **N/A**

----

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license.
ca-nguyen commented 2 years ago

Thanks for the review @shivlaks !

all the locations where a service integration pattern is now accepted also need a test case exercising an "unsupported" integration pattern.

Added the unite tests for unsupported integration_patterns in the latest commit

I also added the integration_pattern arg in the EksCallStep constructor for consistency with the other steps (it was the only one that was missing - omitted previously since it only supports one of the integration patterns)

StepFunctions-Bot commented 2 years ago

AWS CodeBuild CI Report

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository