forked from aws/aws-cdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(stepfunctions-tasks): add EKS call to SFN-tasks (aws#12779)
Taking over the ownership of original PR aws#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*
- Loading branch information
Showing
7 changed files
with
2,039 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
137 changes: 137 additions & 0 deletions
137
packages/@aws-cdk/aws-stepfunctions-tasks/lib/eks/call.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import * as eks from '@aws-cdk/aws-eks'; | ||
import * as iam from '@aws-cdk/aws-iam'; | ||
import * as sfn from '@aws-cdk/aws-stepfunctions'; | ||
import { Construct } from 'constructs'; | ||
import { integrationResourceArn, validatePatternSupported } from '../private/task-utils'; | ||
|
||
/** | ||
* Properties for calling a EKS endpoint with EksCall | ||
* @experimental | ||
*/ | ||
export interface EksCallProps extends sfn.TaskStateBaseProps { | ||
|
||
/** | ||
* The EKS cluster | ||
*/ | ||
readonly cluster: eks.ICluster; | ||
|
||
/** | ||
* HTTP method ("GET", "POST", "PUT", ...) part of HTTP request | ||
*/ | ||
readonly httpMethod: HttpMethods; | ||
|
||
/** | ||
* HTTP path of the Kubernetes REST API operation | ||
* For example: /api/v1/namespaces/default/pods | ||
*/ | ||
readonly httpPath: string; | ||
|
||
/** | ||
* Query Parameters part of HTTP request | ||
* @default - no query parameters | ||
*/ | ||
readonly queryParameters?: { [key: string]: string[] }; | ||
|
||
/** | ||
* Request body part of HTTP request | ||
* @default - No request body | ||
*/ | ||
readonly requestBody?: sfn.TaskInput; | ||
} | ||
|
||
/** | ||
* Call a EKS endpoint as a Task | ||
* | ||
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html | ||
* @experimental | ||
*/ | ||
export class EksCall extends sfn.TaskStateBase { | ||
|
||
private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ | ||
sfn.IntegrationPattern.REQUEST_RESPONSE, | ||
]; | ||
|
||
/** No policies are required due to eks:call is an Http service integration and does not call and EKS API directly | ||
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-eks.html#connect-eks-permissions | ||
*/ | ||
protected readonly taskMetrics?: sfn.TaskMetricsConfig; | ||
protected readonly taskPolicies?: iam.PolicyStatement[]; | ||
|
||
private readonly integrationPattern: sfn.IntegrationPattern; | ||
|
||
private readonly clusterEndpoint: string; | ||
private readonly clusterCertificateAuthorityData: string; | ||
|
||
constructor(scope: Construct, id: string, private readonly props: EksCallProps) { | ||
super(scope, id, props); | ||
this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE; | ||
|
||
validatePatternSupported(this.integrationPattern, EksCall.SUPPORTED_INTEGRATION_PATTERNS); | ||
|
||
try { | ||
this.clusterEndpoint = this.props.cluster.clusterEndpoint; | ||
} catch (e) { | ||
throw new Error('The "clusterEndpoint" property must be specified when using an imported Cluster.'); | ||
} | ||
|
||
try { | ||
this.clusterCertificateAuthorityData = this.props.cluster.clusterCertificateAuthorityData; | ||
} catch (e) { | ||
throw new Error('The "clusterCertificateAuthorityData" property must be specified when using an imported Cluster.'); | ||
} | ||
} | ||
|
||
/** | ||
* Provides the EKS Call service integration task configuration | ||
* @internal | ||
*/ | ||
protected _renderTask(): any { | ||
return { | ||
Resource: integrationResourceArn('eks', 'call', this.integrationPattern), | ||
Parameters: sfn.FieldUtils.renderObject({ | ||
ClusterName: this.props.cluster.clusterName, | ||
CertificateAuthority: this.clusterCertificateAuthorityData, | ||
Endpoint: this.clusterEndpoint, | ||
Method: this.props.httpMethod, | ||
Path: this.props.httpPath, | ||
QueryParameters: this.props.queryParameters, | ||
RequestBody: this.props.requestBody?.value, | ||
}), | ||
}; | ||
} | ||
} | ||
|
||
/** | ||
* Method type of a EKS call | ||
*/ | ||
export enum HttpMethods { | ||
/** | ||
* Retrieve data from a server at the specified resource | ||
*/ | ||
GET = 'GET', | ||
|
||
/** | ||
* Send data to the API endpoint to create or update a resource | ||
*/ | ||
POST = 'POST', | ||
|
||
/** | ||
* Send data to the API endpoint to update or create a resource | ||
*/ | ||
PUT = 'PUT', | ||
|
||
/** | ||
* Delete the resource at the specified endpoint | ||
*/ | ||
DELETE = 'DELETE', | ||
|
||
/** | ||
* Apply partial modifications to the resource | ||
*/ | ||
PATCH = 'PATCH', | ||
|
||
/** | ||
* Retrieve data from a server at the specified resource without the response body | ||
*/ | ||
HEAD = 'HEAD' | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.