From 0f6683394fa6f96d6839b2c107f3dab8045509b4 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Tue, 3 Nov 2020 04:08:36 +0900 Subject: [PATCH] fix(stepfunctions-tasks): Athena* APIs have incorrect supported integration patterns (#11188) The changes made by #11045 seem to support `WAIT_FOR_TASK_TOKEN (.waitForTaskToken)` but according to the documentation, only `Request Response` and `Run a job (.sync)` are supported: https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html closes #11246 ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license* --- .../lib/athena/get-query-execution.ts | 1 - .../lib/athena/get-query-results.ts | 1 - .../lib/athena/start-query-execution.ts | 6 +-- .../lib/athena/stop-query-execution.ts | 1 - .../integ.get-query-execution.expected.json | 3 +- .../integ.get-query-results.expected.json | 3 +- .../integ.start-query-execution.expected.json | 3 +- .../integ.stop-query-execution.expected.json | 3 +- .../test/athena/start-query-execution.test.ts | 47 ++++++++++++++++++- 9 files changed, 57 insertions(+), 11 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.ts index 2f7ea7f53d556..555a42f107cd8 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-execution.ts @@ -26,7 +26,6 @@ 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; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.ts index 781ed8da2d557..4adc8cd4ce379 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/get-query-results.ts @@ -40,7 +40,6 @@ 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; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts index 17328e7e97648..9450800fb6d0b 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/start-query-execution.ts @@ -54,7 +54,7 @@ export class AthenaStartQueryExecution extends sfn.TaskStateBase { private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ sfn.IntegrationPattern.REQUEST_RESPONSE, - sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, + sfn.IntegrationPattern.RUN_JOB, ]; protected readonly taskMetrics?: sfn.TaskMetricsConfig; @@ -87,7 +87,7 @@ export class AthenaStartQueryExecution extends sfn.TaskStateBase { }), ], - actions: ['athena:getDataCatalog', 'athena:startQueryExecution'], + actions: ['athena:getDataCatalog', 'athena:startQueryExecution', 'athena:getQueryExecution'], }), ]; @@ -286,4 +286,4 @@ export interface QueryExecutionContext { * @default - No database */ readonly databaseName?: string; -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/stop-query-execution.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/stop-query-execution.ts index 27c5c606949fc..7a51559a79631 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/stop-query-execution.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/athena/stop-query-execution.ts @@ -24,7 +24,6 @@ export class AthenaStopQueryExecution 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; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.get-query-execution.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.get-query-execution.expected.json index de3041464cf88..b83da65e87a2d 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.get-query-execution.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.get-query-execution.expected.json @@ -36,7 +36,8 @@ { "Action": [ "athena:getDataCatalog", - "athena:startQueryExecution" + "athena:startQueryExecution", + "athena:getQueryExecution" ], "Effect": "Allow", "Resource": [ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.get-query-results.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.get-query-results.expected.json index f593dc785feab..9718e2fa79df9 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.get-query-results.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.get-query-results.expected.json @@ -36,7 +36,8 @@ { "Action": [ "athena:getDataCatalog", - "athena:startQueryExecution" + "athena:startQueryExecution", + "athena:getQueryExecution" ], "Effect": "Allow", "Resource": [ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.start-query-execution.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.start-query-execution.expected.json index 4cff9888545d8..1f5ad33266295 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.start-query-execution.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.start-query-execution.expected.json @@ -36,7 +36,8 @@ { "Action": [ "athena:getDataCatalog", - "athena:startQueryExecution" + "athena:startQueryExecution", + "athena:getQueryExecution" ], "Effect": "Allow", "Resource": [ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.stop-query-execution.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.stop-query-execution.expected.json index 28aaf5d4ab243..a797335db041c 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.stop-query-execution.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/integ.stop-query-execution.expected.json @@ -36,7 +36,8 @@ { "Action": [ "athena:getDataCatalog", - "athena:startQueryExecution" + "athena:startQueryExecution", + "athena:getQueryExecution" ], "Effect": "Allow", "Resource": [ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/start-query-execution.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/start-query-execution.test.ts index 3ab4c0e3202ff..5606f067167b6 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/start-query-execution.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/athena/start-query-execution.test.ts @@ -1,3 +1,4 @@ +import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; import { AthenaStartQueryExecution, EncryptionOption } from '../../lib/athena/start-query-execution'; @@ -53,4 +54,48 @@ describe('Start Query Execution', () => { }, }); }); -}); \ No newline at end of file + + test('sync integrationPattern', () => { + // GIVEN + const stack = new cdk.Stack(); + + // WHEN + const task = new AthenaStartQueryExecution(stack, 'Query', { + integrationPattern: sfn.IntegrationPattern.RUN_JOB, + queryString: 'CREATE DATABASE database', + queryExecutionContext: { + databaseName: 'mydatabase', + }, + resultConfiguration: { + encryptionConfiguration: { encryptionOption: EncryptionOption.S3_MANAGED }, + }, + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::athena:startQueryExecution.sync', + ], + ], + }, + End: true, + Parameters: { + QueryString: 'CREATE DATABASE database', + QueryExecutionContext: { + Database: 'mydatabase', + }, + ResultConfiguration: { + EncryptionConfiguration: { EncryptionOption: EncryptionOption.S3_MANAGED }, + }, + }, + }); + }); +});