-
Notifications
You must be signed in to change notification settings - Fork 4.2k
feat(stepfunctions-tasks): Support for Athena APIs: StartQueryExecution, StopQueryExeuction, GetQueryResults and GetQueryExecution #11045
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
ddcfa72
Add Athena APIs to SFN-tasks
127c453
feat: add Athena APIs to SFN-tasks
5d1078c
add unit tests for Athena API's
a2b5ec0
address PR comments
657c20a
Scope resources for Start Query Execution
f294adc
Add comment preventing cross database access
bd20429
Merge branch 'master' into badyals-sfn-athena
mergify[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.