-
Notifications
You must be signed in to change notification settings - Fork 4k
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): Support for Athena APIs: StartQueryExecuti…
…on, StopQueryExeuction, GetQueryResults and GetQueryExecution (#11045) feat(stepfunctions-tasks): support for Athena APIs: StartQueryExecution, StopQueryExeuction, GetQueryResults and GetQueryExecution **Implementation** Update package `@aws-cdk/aws-stepfunctions-tasks` to include support for Athena **StartQueryExecution**, **StopQueryExeuction**, **GetQueryResults**, **GetQueryExecution** API as per documentation here: https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html Includes support for the following Amazon Athena API calls: * `StartQueryExecution` * `StopQueryExeuction` * `GetQueryResults` * `GetQueryExecution` ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
- Loading branch information
1 parent
75875cc
commit 19180cc
Showing
18 changed files
with
1,977 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
64 changes: 64 additions & 0 deletions
64
packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.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,64 @@ | ||
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 getting a Query Execution | ||
* @experimental | ||
*/ | ||
export interface AthenaGetQueryExecutionProps extends sfn.TaskStateBaseProps { | ||
/** | ||
* Query that will be retrieved | ||
* | ||
* @example 'adfsaf-23trf23-f23rt23' | ||
*/ | ||
readonly queryExecutionId: string; | ||
} | ||
|
||
/** | ||
* Get an Athena Query Execution as a Task | ||
* | ||
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html | ||
* @experimental | ||
*/ | ||
export class AthenaGetQueryExecution extends sfn.TaskStateBase { | ||
|
||
private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ | ||
sfn.IntegrationPattern.REQUEST_RESPONSE, | ||
sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, | ||
]; | ||
|
||
protected readonly taskMetrics?: sfn.TaskMetricsConfig; | ||
protected readonly taskPolicies?: iam.PolicyStatement[]; | ||
|
||
private readonly integrationPattern: sfn.IntegrationPattern; | ||
|
||
constructor(scope: Construct, id: string, private readonly props: AthenaGetQueryExecutionProps) { | ||
super(scope, id, props); | ||
this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE; | ||
|
||
validatePatternSupported(this.integrationPattern, AthenaGetQueryExecution.SUPPORTED_INTEGRATION_PATTERNS); | ||
|
||
this.taskPolicies = [ | ||
new iam.PolicyStatement({ | ||
resources: ['*'], // Grant access to all workgroups as it can not be specified in the request https://docs.aws.amazon.com/athena/latest/ug/workgroups-iam-policy.html | ||
actions: ['athena:getQueryExecution'], | ||
}), | ||
]; | ||
} | ||
|
||
/** | ||
* Provides the Athena get query execution service integration task configuration | ||
* @internal | ||
*/ | ||
protected _renderTask(): any { | ||
return { | ||
Resource: integrationResourceArn('athena', 'getQueryExecution', this.integrationPattern), | ||
Parameters: sfn.FieldUtils.renderObject({ | ||
QueryExecutionId: this.props.queryExecutionId, | ||
}), | ||
}; | ||
} | ||
} | ||
|
89 changes: 89 additions & 0 deletions
89
packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.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,89 @@ | ||
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 getting a Query Results | ||
* @experimental | ||
*/ | ||
export interface AthenaGetQueryResultsProps extends sfn.TaskStateBaseProps { | ||
/** | ||
* Query that will be retrieved | ||
* | ||
* @example 'adfsaf-23trf23-f23rt23' | ||
*/ | ||
readonly queryExecutionId: string; | ||
|
||
/** | ||
* Pagination token | ||
* | ||
* @default - No next token | ||
*/ | ||
readonly nextToken?: string; | ||
|
||
/** | ||
* Max number of results | ||
* | ||
* @default 1000 | ||
*/ | ||
readonly maxResults?: number; | ||
} | ||
|
||
/** | ||
* Get an Athena Query Results as a Task | ||
* | ||
* @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html | ||
* @experimental | ||
*/ | ||
export class AthenaGetQueryResults extends sfn.TaskStateBase { | ||
|
||
private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ | ||
sfn.IntegrationPattern.REQUEST_RESPONSE, | ||
sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, | ||
]; | ||
|
||
protected readonly taskMetrics?: sfn.TaskMetricsConfig; | ||
protected readonly taskPolicies?: iam.PolicyStatement[]; | ||
|
||
private readonly integrationPattern: sfn.IntegrationPattern; | ||
|
||
constructor(scope: Construct, id: string, private readonly props: AthenaGetQueryResultsProps) { | ||
super(scope, id, props); | ||
this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE; | ||
|
||
validatePatternSupported(this.integrationPattern, AthenaGetQueryResults.SUPPORTED_INTEGRATION_PATTERNS); | ||
|
||
const policyStatements = [ | ||
new iam.PolicyStatement({ | ||
resources: ['*'], // Workgroup can not be specified in the request https://docs.aws.amazon.com/athena/latest/ug/workgroups-iam-policy.html | ||
actions: ['athena:getQueryResults'], | ||
}), | ||
]; | ||
|
||
policyStatements.push( | ||
new iam.PolicyStatement({ | ||
actions: ['s3:GetObject'], | ||
resources: ['*'], // To stream query results successfully the IAM principal must have permissions to the Amazon S3 GetObject action for the Athena query results location https://docs.amazonaws.cn/en_us/athena/latest/APIReference/API_GetQueryResults.html | ||
}), | ||
); | ||
|
||
this.taskPolicies = policyStatements; | ||
} | ||
|
||
/** | ||
* Provides the Athena get query results service integration task configuration | ||
* @internal | ||
*/ | ||
protected _renderTask(): any { | ||
return { | ||
Resource: integrationResourceArn('athena', 'getQueryResults', this.integrationPattern), | ||
Parameters: sfn.FieldUtils.renderObject({ | ||
QueryExecutionId: this.props.queryExecutionId, | ||
NextToken: this.props.nextToken, | ||
MaxResults: this.props.maxResults, | ||
}), | ||
}; | ||
} | ||
} | ||
|
Oops, something went wrong.