Skip to content

Commit 296a10d

Browse files
authored
feat(stepfunctions-tasks): add EKS call to SFN-tasks (#12779)
Taking over the ownership of original PR #11738 feat(stepfunctions-tasks): support for EKS Call Implementation Update package @aws-cdk/aws-stepfunctions-tasks to include support for EKS Call API as per documentation here: https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html Includes support for the following Amazon EKS API calls: eks:call ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 45cf387 commit 296a10d

File tree

7 files changed

+2039
-0
lines changed

7 files changed

+2039
-0
lines changed

packages/@aws-cdk/aws-stepfunctions-tasks/README.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aw
5454
- [Cancel Step](#cancel-step)
5555
- [Modify Instance Fleet](#modify-instance-fleet)
5656
- [Modify Instance Group](#modify-instance-group)
57+
- [EKS](#eks)
58+
- [Call](#call)
5759
- [Glue](#glue)
5860
- [Glue DataBrew](#glue-databrew)
5961
- [Lambda](#lambda)
@@ -664,6 +666,37 @@ new tasks.EmrModifyInstanceGroupByName(stack, 'Task', {
664666
});
665667
```
666668

669+
## EKS
670+
671+
Step Functions supports Amazon EKS through the service integration pattern.
672+
The service integration APIs correspond to Amazon EKS APIs.
673+
674+
[Read more](https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html) about the differences when using these service integrations.
675+
676+
### Call
677+
678+
Read and write Kubernetes resource objects via a Kubernetes API endpoint.
679+
Corresponds to the [`call`](https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html) API in Step Functions Connector.
680+
681+
The following code snippet includes a Task state that uses eks:call to list the pods.
682+
683+
```ts
684+
import * as eks from '@aws-cdk/aws-eks';
685+
import * as sfn from '@aws-cdk/aws-stepfunctions';
686+
import * as tasks from '@aws-cdk/aws-stepfunctions-tasks';
687+
688+
const myEksCluster = new eks.Cluster(this, 'my sample cluster', {
689+
version: eks.KubernetesVersion.V1_18,
690+
clusterName: 'myEksCluster',
691+
});
692+
693+
new tasks.EksCall(stack, 'Call a EKS Endpoint', {
694+
cluster: myEksCluster,
695+
httpMethod: MethodType.GET,
696+
httpPath: '/api/v1/namespaces/default/pods',
697+
});
698+
```
699+
667700
## Glue
668701

669702
Step Functions supports [AWS Glue](https://docs.aws.amazon.com/step-functions/latest/dg/connect-glue.html) through the service integration pattern.
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
import * as eks from '@aws-cdk/aws-eks';
2+
import * as iam from '@aws-cdk/aws-iam';
3+
import * as sfn from '@aws-cdk/aws-stepfunctions';
4+
import { Construct } from 'constructs';
5+
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils';
6+
7+
/**
8+
* Properties for calling a EKS endpoint with EksCall
9+
* @experimental
10+
*/
11+
export interface EksCallProps extends sfn.TaskStateBaseProps {
12+
13+
/**
14+
* The EKS cluster
15+
*/
16+
readonly cluster: eks.ICluster;
17+
18+
/**
19+
* HTTP method ("GET", "POST", "PUT", ...) part of HTTP request
20+
*/
21+
readonly httpMethod: HttpMethods;
22+
23+
/**
24+
* HTTP path of the Kubernetes REST API operation
25+
* For example: /api/v1/namespaces/default/pods
26+
*/
27+
readonly httpPath: string;
28+
29+
/**
30+
* Query Parameters part of HTTP request
31+
* @default - no query parameters
32+
*/
33+
readonly queryParameters?: { [key: string]: string[] };
34+
35+
/**
36+
* Request body part of HTTP request
37+
* @default - No request body
38+
*/
39+
readonly requestBody?: sfn.TaskInput;
40+
}
41+
42+
/**
43+
* Call a EKS endpoint as a Task
44+
*
45+
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html
46+
* @experimental
47+
*/
48+
export class EksCall extends sfn.TaskStateBase {
49+
50+
private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [
51+
sfn.IntegrationPattern.REQUEST_RESPONSE,
52+
];
53+
54+
/** No policies are required due to eks:call is an Http service integration and does not call and EKS API directly
55+
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html#connect-eks-permissions
56+
*/
57+
protected readonly taskMetrics?: sfn.TaskMetricsConfig;
58+
protected readonly taskPolicies?: iam.PolicyStatement[];
59+
60+
private readonly integrationPattern: sfn.IntegrationPattern;
61+
62+
private readonly clusterEndpoint: string;
63+
private readonly clusterCertificateAuthorityData: string;
64+
65+
constructor(scope: Construct, id: string, private readonly props: EksCallProps) {
66+
super(scope, id, props);
67+
this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE;
68+
69+
validatePatternSupported(this.integrationPattern, EksCall.SUPPORTED_INTEGRATION_PATTERNS);
70+
71+
try {
72+
this.clusterEndpoint = this.props.cluster.clusterEndpoint;
73+
} catch (e) {
74+
throw new Error('The "clusterEndpoint" property must be specified when using an imported Cluster.');
75+
}
76+
77+
try {
78+
this.clusterCertificateAuthorityData = this.props.cluster.clusterCertificateAuthorityData;
79+
} catch (e) {
80+
throw new Error('The "clusterCertificateAuthorityData" property must be specified when using an imported Cluster.');
81+
}
82+
}
83+
84+
/**
85+
* Provides the EKS Call service integration task configuration
86+
* @internal
87+
*/
88+
protected _renderTask(): any {
89+
return {
90+
Resource: integrationResourceArn('eks', 'call', this.integrationPattern),
91+
Parameters: sfn.FieldUtils.renderObject({
92+
ClusterName: this.props.cluster.clusterName,
93+
CertificateAuthority: this.clusterCertificateAuthorityData,
94+
Endpoint: this.clusterEndpoint,
95+
Method: this.props.httpMethod,
96+
Path: this.props.httpPath,
97+
QueryParameters: this.props.queryParameters,
98+
RequestBody: this.props.requestBody?.value,
99+
}),
100+
};
101+
}
102+
}
103+
104+
/**
105+
* Method type of a EKS call
106+
*/
107+
export enum HttpMethods {
108+
/**
109+
* Retrieve data from a server at the specified resource
110+
*/
111+
GET = 'GET',
112+
113+
/**
114+
* Send data to the API endpoint to create or update a resource
115+
*/
116+
POST = 'POST',
117+
118+
/**
119+
* Send data to the API endpoint to update or create a resource
120+
*/
121+
PUT = 'PUT',
122+
123+
/**
124+
* Delete the resource at the specified endpoint
125+
*/
126+
DELETE = 'DELETE',
127+
128+
/**
129+
* Apply partial modifications to the resource
130+
*/
131+
PATCH = 'PATCH',
132+
133+
/**
134+
* Retrieve data from a server at the specified resource without the response body
135+
*/
136+
HEAD = 'HEAD'
137+
}

packages/@aws-cdk/aws-stepfunctions-tasks/lib/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,4 @@ export * from './athena/stop-query-execution';
4444
export * from './athena/get-query-execution';
4545
export * from './athena/get-query-results';
4646
export * from './databrew/start-job-run';
47+
export * from './eks/call';

packages/@aws-cdk/aws-stepfunctions-tasks/package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
"@aws-cdk/aws-ecr": "0.0.0",
8282
"@aws-cdk/aws-ecr-assets": "0.0.0",
8383
"@aws-cdk/aws-ecs": "0.0.0",
84+
"@aws-cdk/aws-eks": "0.0.0",
8485
"@aws-cdk/aws-glue": "0.0.0",
8586
"@aws-cdk/aws-iam": "0.0.0",
8687
"@aws-cdk/aws-kms": "0.0.0",
@@ -103,6 +104,7 @@
103104
"@aws-cdk/aws-ecr": "0.0.0",
104105
"@aws-cdk/aws-ecr-assets": "0.0.0",
105106
"@aws-cdk/aws-ecs": "0.0.0",
107+
"@aws-cdk/aws-eks": "0.0.0",
106108
"@aws-cdk/aws-glue": "0.0.0",
107109
"@aws-cdk/aws-iam": "0.0.0",
108110
"@aws-cdk/aws-kms": "0.0.0",

0 commit comments

Comments
 (0)