From 16db4109d7b730e776f052a034ed29f6608e8b85 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Thu, 29 Oct 2020 11:49:41 +0900 Subject: [PATCH 1/2] fix(stepfunctions-tasks): Athena integrationPattern has incorrect pattern --- .../lib/athena/get-query-execution.ts | 1 - .../lib/athena/get-query-results.ts | 1 - .../lib/athena/start-query-execution.ts | 4 +- .../lib/athena/stop-query-execution.ts | 1 - .../test/athena/start-query-execution.test.ts | 47 ++++++++++++++++++- 5 files changed, 48 insertions(+), 6 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..4cdd5f29fbc05 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; @@ -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/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 }, + }, + }, + }); + }); +}); From 7f7a9e4a59330480943527e7bcc59791275b35e6 Mon Sep 17 00:00:00 2001 From: Takumi Akiyama Date: Thu, 29 Oct 2020 16:42:38 +0900 Subject: [PATCH 2/2] add athena:getQueryExecution policy for startQueryExecution.sync reference: https://docs.aws.amazon.com/step-functions/latest/dg/athena-iam.html --- .../lib/athena/start-query-execution.ts | 2 +- .../test/athena/integ.get-query-execution.expected.json | 3 ++- .../test/athena/integ.get-query-results.expected.json | 3 ++- .../test/athena/integ.start-query-execution.expected.json | 3 ++- .../test/athena/integ.stop-query-execution.expected.json | 3 ++- 5 files changed, 9 insertions(+), 5 deletions(-) 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 4cdd5f29fbc05..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 @@ -87,7 +87,7 @@ export class AthenaStartQueryExecution extends sfn.TaskStateBase { }), ], - actions: ['athena:getDataCatalog', 'athena:startQueryExecution'], + actions: ['athena:getDataCatalog', 'athena:startQueryExecution', 'athena:getQueryExecution'], }), ]; 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": [