From 9f9ed0b9f2d5bcbd24bcc031bcbc423147860398 Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Sun, 14 Feb 2021 12:43:44 +0530 Subject: [PATCH 1/8] feat(stepfunctions-tasks): Support invoking APIGW REST and HTTP APIs --- .../aws-stepfunctions-tasks/README.md | 40 ++ .../lib/apigateway/common.ts | 154 +++++++ .../lib/apigateway/index.ts | 3 + .../lib/apigateway/invoke-http-api.ts | 61 +++ .../lib/apigateway/invoke-rest-api.ts | 50 +++ .../aws-stepfunctions-tasks/lib/index.ts | 1 + .../aws-stepfunctions-tasks/package.json | 6 + .../integ.invoke-http-api.expected.json | 263 ++++++++++++ .../test/apigateway/integ.invoke-http-api.ts | 48 +++ .../integ.invoke-rest-api.expected.json | 394 ++++++++++++++++++ .../test/apigateway/integ.invoke-rest-api.ts | 43 ++ .../test/apigateway/invoke-http-api.test.ts | 131 ++++++ .../test/apigateway/invoke-rest-api.test.ts | 136 ++++++ 13 files changed, 1330 insertions(+) create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/README.md b/packages/@aws-cdk/aws-stepfunctions-tasks/README.md index d7c2d1498394d..31eb143e74307 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/README.md +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/README.md @@ -28,6 +28,9 @@ This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aw - [ResultPath](#resultpath) - [Parameters](#task-parameters-from-the-state-json) - [Evaluate Expression](#evaluate-expression) +- [API Gateway](#api-gateway) + - [InvokeRestApi](#invoke-rest-api) + - [InvokeHttpApi](#invoke-http-api) - [Athena](#athena) - [StartQueryExecution](#startQueryExecution) - [GetQueryExecution](#getQueryExecution) @@ -215,6 +218,43 @@ The `EvaluateExpression` supports a `runtime` prop to specify the Lambda runtime to use to evaluate the expression. Currently, only runtimes of the Node.js family are supported. +## API Gateway + +Step Functions support [API Gateway](https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html) through the service integration pattern. + +### Invoke REST API + +The `InvokeApiGatewayRestApi` calls the REST API endpoint. + +```ts +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as tasks from `@aws-cdk/aws-stepfunctions-tasks`; + +const restApi = new apigateway.RestApi(stack, 'MyRestApi'); + +const invokeTask = new tasks.InvokeApiGatewayRestApi(stack, 'Invoke REST API', { + api: restApi, + stageName: 'prod', + method: HttpMethod.GET, +}); +``` + +### Invoke HTTP API + +The `InvokeApiGatewayHttpApi` calls the HTTP API endpoint. + +```ts +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as tasks from `@aws-cdk/aws-stepfunctions-tasks`; + +const httpApi = new apigatewayv2.HttpApi(stack, 'MyHttpApi'); + +const invokeTask = new tasks.InvokeApiGatewayHttpApi(stack, 'Invoke HTTP API', { + api: httpApi, + method: HttpMethod.GET, +}); +``` + ## Athena Step Functions supports [Athena](https://docs.aws.amazon.com/step-functions/latest/dg/connect-athena.html) through the service integration pattern. diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts new file mode 100644 index 0000000000000..85b599af804a8 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts @@ -0,0 +1,154 @@ +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'; + +/** Http Methods that API Gateway supports */ +export enum HttpMethod { + /** Retreive data from a server at the specified resource */ + GET = 'GET', + + /** Send data to the API endpoint to create or udpate 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', + + /** Retreive data from a server at the specified resource without the response body */ + HEAD = 'HEAD', + + /** Return data describing what other methods and operations the server supports */ + OPTIONS = 'OPTIONS' +} + +/** + * The authentication method used to call the endpoint + */ +export enum AuthType { + /** Call the API direclty with no authorization method */ + NO_AUTH = 'NO_AUTH', + + /** * Use the IAM role associated with the current state machine for authorization */ + IAM_ROLE = 'IAM_ROLE', + + /** Use the resource policy of the API for authorization */ + RESOURCE_POLICY = 'RESOURCE_POLICY', +} + +/** + * Base ApiGateway Invoke Task Props + */ +export interface BaseInvokeApiGatewayApiProps extends sfn.TaskStateBaseProps { + /** + * Http method for the API + */ + readonly method: HttpMethod; + + /** + * HTTP request information that does not relate to contents of the request + * @default - No headers + */ + readonly headers?: sfn.TaskInput; + + + /** + * Path parameters appended after API endpoint + * @default - No path + */ + readonly path?: string; + + /** + * Query strings attatched to end of request + * @default - No query parameters + */ + readonly queryParameters?: sfn.TaskInput; + + /** + * HTTP Request body + * @default - No requestBody + */ + readonly requestBody?: sfn.TaskInput; + + /** + * Authentication methods + * @default AuthType.NO_AUTH + */ + readonly authType?: AuthType; +} + +/** + * Base ApiGateway Invoke Task + */ +export abstract class BaseInvokeApiGatewayApi extends sfn.TaskStateBase { + private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ + sfn.IntegrationPattern.REQUEST_RESPONSE, + sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, + ]; + + private readonly baseProps: BaseInvokeApiGatewayApiProps; + private readonly integrationPattern: sfn.IntegrationPattern; + + protected abstract readonly apiEndpoint: string; + protected abstract readonly arnForExecuteApi: string; + protected abstract readonly stageName?: string; + + constructor(scope: Construct, id: string, props: BaseInvokeApiGatewayApiProps) { + super(scope, id, props); + + this.baseProps = props; + this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE; + validatePatternSupported(this.integrationPattern, BaseInvokeApiGatewayApi.SUPPORTED_INTEGRATION_PATTERNS); + } + + /** + * @internal + */ + protected _renderTask() { + return { + Resource: integrationResourceArn('apigateway', 'invoke', this.integrationPattern), + Parameters: sfn.FieldUtils.renderObject({ + ApiEndpoint: this.apiEndpoint, + Method: this.baseProps.method, + Headers: this.baseProps.headers?.value, + Stage: this.stageName, + Path: this.baseProps.path, + QueryParameters: this.baseProps.queryParameters?.value, + RequestBody: this.baseProps.requestBody?.value, + AuthType: this.baseProps.authType ? this.baseProps.authType : 'NO_AUTH', + }), + }; + } + + protected createPolicyStatements(): iam.PolicyStatement[] { + if (this.baseProps.authType === AuthType.IAM_ROLE) { + return [ + new iam.PolicyStatement({ + resources: [this.arnForExecuteApi], + actions: ['ExecuteAPI:Invoke'], + }), + ]; + } else if (this.baseProps.authType === AuthType.RESOURCE_POLICY) { + if (!sfn.FieldUtils.containsTaskToken(this.baseProps.headers)) { + throw new Error('Task Token is required in `headers` Use JsonPath.taskToken to set the token.'); + } + return [ + new iam.PolicyStatement({ + resources: [this.arnForExecuteApi], + actions: ['ExecuteAPI:Invoke'], + conditions: { + StringEquals: { + 'aws:SourceArn': '*', + }, + }, + }), + ]; + } + return []; + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts new file mode 100644 index 0000000000000..364273a56e472 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts @@ -0,0 +1,3 @@ +export * from './common'; +export * from './invoke-rest-api'; +export * from './invoke-http-api'; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts new file mode 100644 index 0000000000000..a49d5c025c5e3 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts @@ -0,0 +1,61 @@ +import * as apigatewayv2 from '@aws-cdk/aws-apigatewayv2'; +import * as iam from '@aws-cdk/aws-iam'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as cdk from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import { BaseInvokeApiGatewayApi, BaseInvokeApiGatewayApiProps } from './common'; + +/** + * Properties for invoking an HTTP API Endpoint + */ +export interface InvokeApiGatewayHttpApiProps extends BaseInvokeApiGatewayApiProps { + /** + * API to call + */ + readonly api: apigatewayv2.IHttpApi; + + /** + * Name of the stage where the API is deployed to in API Gateway + * @default '$default' + */ + readonly stageName?: string; +} + +/** + * Invoke HTTP API endpoint as a Task + * + * @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html + */ +export class InvokeApiGatewayHttpApi extends BaseInvokeApiGatewayApi { + protected readonly taskMetrics?: sfn.TaskMetricsConfig | undefined; + protected readonly taskPolicies?: iam.PolicyStatement[] | undefined; + + protected readonly apiEndpoint: string; + protected readonly arnForExecuteApi: string; + protected readonly stageName?: string; + + constructor(scope: Construct, id: string, private readonly props: InvokeApiGatewayHttpApiProps) { + super(scope, id, props); + + this.apiEndpoint = this.getApiEndpoint(); + this.arnForExecuteApi = this.getArnForExecuteApi(); + + this.taskPolicies = this.createPolicyStatements(); + } + + private getApiEndpoint(): string { + const apiStack = cdk.Stack.of(this.props.api); + return `${this.props.api.httpApiId}.execute-api.${apiStack.region}.${apiStack.urlSuffix}`; + } + + private getArnForExecuteApi(): string { + const { api, stageName, method, path } = this.props; + + return cdk.Stack.of(api).formatArn({ + service: 'execute-api', + resource: api.httpApiId, + sep: '/', + resourceName: `${stageName}/${method}${path}`, + }); + } +} diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts new file mode 100644 index 0000000000000..298d5b6775133 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts @@ -0,0 +1,50 @@ +import * as apigateway from '@aws-cdk/aws-apigateway'; +import * as iam from '@aws-cdk/aws-iam'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as cdk from '@aws-cdk/core'; +import { Construct } from 'constructs'; +import { BaseInvokeApiGatewayApi, BaseInvokeApiGatewayApiProps } from './common'; + +/** + * Properties for invoking an REST API Endpoint + */ +export interface InvokeApiGatewayRestApiProps extends BaseInvokeApiGatewayApiProps { + /** + * API to call + */ + readonly api: apigateway.IRestApi; + + /** + * Name of the stage where the API is deployed to in API Gateway + */ + readonly stageName: string; +} + +/** + * Invoke REST API endpoint as a Task + * + * @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html + */ +export class InvokeApiGatewayRestApi extends BaseInvokeApiGatewayApi { + protected readonly taskMetrics?: sfn.TaskMetricsConfig | undefined; + protected readonly taskPolicies?: iam.PolicyStatement[] | undefined; + + protected readonly apiEndpoint: string; + protected readonly arnForExecuteApi: string; + protected readonly stageName?: string; + + constructor(scope: Construct, id: string, private readonly props: InvokeApiGatewayRestApiProps) { + super(scope, id, props); + + this.apiEndpoint = this.getApiEndpoint(); + this.arnForExecuteApi = props.api.arnForExecuteApi(props.method, props.path, props.stageName); + this.stageName = props.stageName; + + this.taskPolicies = this.createPolicyStatements(); + } + + private getApiEndpoint(): string { + const apiStack = cdk.Stack.of(this.props.api); + return `${this.props.api.restApiId}.execute-api.${apiStack.region}.${apiStack.urlSuffix}`; + } +} diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/index.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/index.ts index 32e684f6d1adf..7b566bbbe4dad 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/index.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/index.ts @@ -45,3 +45,4 @@ export * from './athena/get-query-execution'; export * from './athena/get-query-results'; export * from './databrew/start-job-run'; export * from './eks/call'; +export * from './apigateway'; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/package.json b/packages/@aws-cdk/aws-stepfunctions-tasks/package.json index a6137f570b1a3..b18cd8fc7704c 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/package.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/package.json @@ -72,6 +72,9 @@ "pkglint": "0.0.0" }, "dependencies": { + "@aws-cdk/aws-apigateway": "0.0.0", + "@aws-cdk/aws-apigatewayv2": "0.0.0", + "@aws-cdk/aws-apigatewayv2-integrations": "0.0.0", "@aws-cdk/aws-batch": "0.0.0", "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/aws-codebuild": "0.0.0", @@ -95,6 +98,9 @@ }, "homepage": "https://github.com/aws/aws-cdk", "peerDependencies": { + "@aws-cdk/aws-apigateway": "0.0.0", + "@aws-cdk/aws-apigatewayv2": "0.0.0", + "@aws-cdk/aws-apigatewayv2-integrations": "0.0.0", "@aws-cdk/aws-batch": "0.0.0", "@aws-cdk/aws-cloudwatch": "0.0.0", "@aws-cdk/aws-codebuild": "0.0.0", diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json new file mode 100644 index 0000000000000..0db21ee2251a2 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json @@ -0,0 +1,263 @@ +{ + "Resources": { + "MyHttpApi8AEAAC21": { + "Type": "AWS::ApiGatewayV2::Api", + "Properties": { + "Name": "MyHttpApi", + "ProtocolType": "HTTP" + } + }, + "MyHttpApiDefaultStageDCB9BC49": { + "Type": "AWS::ApiGatewayV2::Stage", + "Properties": { + "ApiId": { + "Ref": "MyHttpApi8AEAAC21" + }, + "StageName": "$default", + "AutoDeploy": true + } + }, + "MyHttpApiANYInvokeHttpApiIntegMyHttpApiANY146E68A6PermissionAB056FD4": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "HelloHandler2E4FBA4D", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyHttpApi8AEAAC21" + }, + "/*/*/" + ] + ] + } + } + }, + "MyHttpApiANYC3543576": { + "Type": "AWS::ApiGatewayV2::Route", + "Properties": { + "ApiId": { + "Ref": "MyHttpApi8AEAAC21" + }, + "RouteKey": "ANY /", + "AuthorizationScopes": [], + "Target": { + "Fn::Join": [ + "", + [ + "integrations/", + { + "Ref": "MyHttpApiHttpIntegration71abbf75d6f8e5ea93ec2120c0d78b75D3F1C5AA" + } + ] + ] + } + } + }, + "MyHttpApiHttpIntegration71abbf75d6f8e5ea93ec2120c0d78b75D3F1C5AA": { + "Type": "AWS::ApiGatewayV2::Integration", + "Properties": { + "ApiId": { + "Ref": "MyHttpApi8AEAAC21" + }, + "IntegrationType": "AWS_PROXY", + "IntegrationUri": { + "Fn::GetAtt": [ + "HelloHandler2E4FBA4D", + "Arn" + ] + }, + "PayloadFormatVersion": "2.0" + } + }, + "HelloHandlerServiceRole11EF7C63": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "HelloHandler2E4FBA4D": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async function(event, context) { return { statusCode: 200, body: \"hello, world!\" }; };" + }, + "Role": { + "Fn::GetAtt": [ + "HelloHandlerServiceRole11EF7C63", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "nodejs10.x" + }, + "DependsOn": [ + "HelloHandlerServiceRole11EF7C63" + ] + }, + "StateMachineRoleB840431D": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "states.", + { + "Ref": "AWS::Region" + }, + ".amazonaws.com" + ] + ] + } + } + } + ], + "Version": "2012-10-17" + } + } + }, + "StateMachineRoleDefaultPolicyDF1E6607": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "ExecuteAPI:Invoke", + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyHttpApi8AEAAC21" + }, + "/undefined/GETundefined" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", + "Roles": [ + { + "Ref": "StateMachineRoleB840431D" + } + ] + } + }, + "StateMachine2E01A3A5": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRoleB840431D", + "Arn" + ] + }, + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"Invoke APIGW\",\"States\":{\"Invoke APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::apigateway:invoke\",\"Parameters\":{\"ApiEndpoint\":\"", + { + "Ref": "MyHttpApi8AEAAC21" + }, + ".execute-api.", + { + "Ref": "AWS::Region" + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "\",\"Method\":\"GET\",\"AuthType\":\"IAM_ROLE\"}}},\"TimeoutSeconds\":30}" + ] + ] + } + }, + "DependsOn": [ + "StateMachineRoleDefaultPolicyDF1E6607", + "StateMachineRoleB840431D" + ] + } + }, + "Outputs": { + "stateMachineArn": { + "Value": { + "Ref": "StateMachine2E01A3A5" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts new file mode 100644 index 0000000000000..f25b34218a52c --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts @@ -0,0 +1,48 @@ +import * as apigatewayv2 from '@aws-cdk/aws-apigatewayv2'; +import * as integrations from '@aws-cdk/aws-apigatewayv2-integrations'; +import * as lambda from '@aws-cdk/aws-lambda'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as cdk from '@aws-cdk/core'; +import { AuthType, HttpMethod, InvokeApiGatewayHttpApi } from '../../lib'; + +/* + * Stack verification steps: + * * aws stepfunctions start-execution --state-machine-arn : should return execution arn + * + * * aws stepfunctions describe-execution --execution-arn --query 'status': should return status as SUCCEEDED + * * aws stepfunctions describe-execution --execution-arn --query 'output': should return the number \"hello, world!\" + */ + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'InvokeHttpApiInteg'); +const httpApi = new apigatewayv2.HttpApi(stack, 'MyHttpApi'); + +const handler = new lambda.Function(stack, 'HelloHandler', { + runtime: lambda.Runtime.NODEJS_10_X, + handler: 'index.handler', + code: new lambda.InlineCode('exports.handler = async function(event, context) { return { statusCode: 200, body: "hello, world!" }; };'), +}); +httpApi.addRoutes({ + path: '/', + integration: new integrations.LambdaProxyIntegration({ + handler, + }), +}); + +const invokeJob = new InvokeApiGatewayHttpApi(stack, 'Invoke APIGW', { + api: httpApi, + method: HttpMethod.GET, + authType: AuthType.IAM_ROLE, + outputPath: sfn.JsonPath.stringAt('$.ResponseBody'), +}); + +const chain = sfn.Chain.start(invokeJob); + +const sm = new sfn.StateMachine(stack, 'StateMachine', { + definition: chain, + timeout: cdk.Duration.seconds(30), +}); + +new cdk.CfnOutput(stack, 'stateMachineArn', { + value: sm.stateMachineArn, +}); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json new file mode 100644 index 0000000000000..c5f0305d25485 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json @@ -0,0 +1,394 @@ +{ + "Resources": { + "MyRestApi2D1F47A9": { + "Type": "AWS::ApiGateway::RestApi", + "Properties": { + "Name": "MyRestApi" + } + }, + "MyRestApiCloudWatchRoleD4042E8E": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "apigateway.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AmazonAPIGatewayPushToCloudWatchLogs" + ] + ] + } + ] + } + }, + "MyRestApiAccount2FB6DB7A": { + "Type": "AWS::ApiGateway::Account", + "Properties": { + "CloudWatchRoleArn": { + "Fn::GetAtt": [ + "MyRestApiCloudWatchRoleD4042E8E", + "Arn" + ] + } + }, + "DependsOn": [ + "MyRestApi2D1F47A9" + ] + }, + "MyRestApiDeploymentB555B582d61dc696e12272a0706c826196fa8d62": { + "Type": "AWS::ApiGateway::Deployment", + "Properties": { + "RestApiId": { + "Ref": "MyRestApi2D1F47A9" + }, + "Description": "Automatically created by the RestApi construct" + }, + "DependsOn": [ + "MyRestApiANY05143F93" + ] + }, + "MyRestApiDeploymentStageprodC33B8E5F": { + "Type": "AWS::ApiGateway::Stage", + "Properties": { + "RestApiId": { + "Ref": "MyRestApi2D1F47A9" + }, + "DeploymentId": { + "Ref": "MyRestApiDeploymentB555B582d61dc696e12272a0706c826196fa8d62" + }, + "StageName": "prod" + } + }, + "MyRestApiANYApiPermissionInvokeRestApiIntegMyRestApi9DA14B28ANY5B4931EE": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/", + { + "Ref": "MyRestApiDeploymentStageprodC33B8E5F" + }, + "/*/" + ] + ] + } + } + }, + "MyRestApiANYApiPermissionTestInvokeRestApiIntegMyRestApi9DA14B28ANY922900DE": { + "Type": "AWS::Lambda::Permission", + "Properties": { + "Action": "lambda:InvokeFunction", + "FunctionName": { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "Principal": "apigateway.amazonaws.com", + "SourceArn": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/test-invoke-stage/*/" + ] + ] + } + } + }, + "MyRestApiANY05143F93": { + "Type": "AWS::ApiGateway::Method", + "Properties": { + "HttpMethod": "ANY", + "ResourceId": { + "Fn::GetAtt": [ + "MyRestApi2D1F47A9", + "RootResourceId" + ] + }, + "RestApiId": { + "Ref": "MyRestApi2D1F47A9" + }, + "AuthorizationType": "NONE", + "Integration": { + "IntegrationHttpMethod": "POST", + "Type": "AWS_PROXY", + "Uri": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":apigateway:", + { + "Ref": "AWS::Region" + }, + ":lambda:path/2015-03-31/functions/", + { + "Fn::GetAtt": [ + "Hello4A628BD4", + "Arn" + ] + }, + "/invocations" + ] + ] + } + } + } + }, + "HelloServiceRole1E55EA16": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": "lambda.amazonaws.com" + } + } + ], + "Version": "2012-10-17" + }, + "ManagedPolicyArns": [ + { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":iam::aws:policy/service-role/AWSLambdaBasicExecutionRole" + ] + ] + } + ] + } + }, + "Hello4A628BD4": { + "Type": "AWS::Lambda::Function", + "Properties": { + "Code": { + "ZipFile": "exports.handler = async function(event, context) { return { statusCode: 200, body: \"hello, world!\" }; };" + }, + "Role": { + "Fn::GetAtt": [ + "HelloServiceRole1E55EA16", + "Arn" + ] + }, + "Handler": "index.handler", + "Runtime": "nodejs10.x" + }, + "DependsOn": [ + "HelloServiceRole1E55EA16" + ] + }, + "StateMachineRoleB840431D": { + "Type": "AWS::IAM::Role", + "Properties": { + "AssumeRolePolicyDocument": { + "Statement": [ + { + "Action": "sts:AssumeRole", + "Effect": "Allow", + "Principal": { + "Service": { + "Fn::Join": [ + "", + [ + "states.", + { + "Ref": "AWS::Region" + }, + ".amazonaws.com" + ] + ] + } + } + } + ], + "Version": "2012-10-17" + } + } + }, + "StateMachineRoleDefaultPolicyDF1E6607": { + "Type": "AWS::IAM::Policy", + "Properties": { + "PolicyDocument": { + "Statement": [ + { + "Action": "ExecuteAPI:Invoke", + "Effect": "Allow", + "Resource": { + "Fn::Join": [ + "", + [ + "arn:", + { + "Ref": "AWS::Partition" + }, + ":execute-api:", + { + "Ref": "AWS::Region" + }, + ":", + { + "Ref": "AWS::AccountId" + }, + ":", + { + "Ref": "MyRestApi2D1F47A9" + }, + "/prod/GET/*" + ] + ] + } + } + ], + "Version": "2012-10-17" + }, + "PolicyName": "StateMachineRoleDefaultPolicyDF1E6607", + "Roles": [ + { + "Ref": "StateMachineRoleB840431D" + } + ] + } + }, + "StateMachine2E01A3A5": { + "Type": "AWS::StepFunctions::StateMachine", + "Properties": { + "RoleArn": { + "Fn::GetAtt": [ + "StateMachineRoleB840431D", + "Arn" + ] + }, + "DefinitionString": { + "Fn::Join": [ + "", + [ + "{\"StartAt\":\"Invoke APIGW\",\"States\":{\"Invoke APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", + { + "Ref": "AWS::Partition" + }, + ":states:::apigateway:invoke\",\"Parameters\":{\"ApiEndpoint\":\"", + { + "Ref": "MyRestApi2D1F47A9" + }, + ".execute-api.", + { + "Ref": "AWS::Region" + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "\",\"Method\":\"GET\",\"Stage\":\"prod\",\"AuthType\":\"IAM_ROLE\"}}},\"TimeoutSeconds\":30}" + ] + ] + } + }, + "DependsOn": [ + "StateMachineRoleDefaultPolicyDF1E6607", + "StateMachineRoleB840431D" + ] + } + }, + "Outputs": { + "MyRestApiEndpoint4C55E4CB": { + "Value": { + "Fn::Join": [ + "", + [ + "https://", + { + "Ref": "MyRestApi2D1F47A9" + }, + ".execute-api.", + { + "Ref": "AWS::Region" + }, + ".", + { + "Ref": "AWS::URLSuffix" + }, + "/", + { + "Ref": "MyRestApiDeploymentStageprodC33B8E5F" + }, + "/" + ] + ] + } + }, + "stateMachineArn": { + "Value": { + "Ref": "StateMachine2E01A3A5" + } + } + } +} \ No newline at end of file diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts new file mode 100644 index 0000000000000..70e2a4e84b647 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts @@ -0,0 +1,43 @@ +import * as apigateway from '@aws-cdk/aws-apigateway'; +import * as lambda from '@aws-cdk/aws-lambda'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as cdk from '@aws-cdk/core'; +import { AuthType, HttpMethod, InvokeApiGatewayRestApi } from '../../lib'; + +/* + * Stack verification steps: + * * aws stepfunctions start-execution --state-machine-arn : should return execution arn + * + * * aws stepfunctions describe-execution --execution-arn --query 'status': should return status as SUCCEEDED + * * aws stepfunctions describe-execution --execution-arn --query 'output': should return the number \"hello, world!\" + */ + +const app = new cdk.App(); +const stack = new cdk.Stack(app, 'InvokeRestApiInteg'); +const restApi = new apigateway.RestApi(stack, 'MyRestApi'); + +const hello = new apigateway.LambdaIntegration(new lambda.Function(stack, 'Hello', { + runtime: lambda.Runtime.NODEJS_10_X, + handler: 'index.handler', + code: new lambda.InlineCode('exports.handler = async function(event, context) { return { statusCode: 200, body: "hello, world!" }; };'), +})); +restApi.root.addMethod('ANY', hello); + +const invokeJob = new InvokeApiGatewayRestApi(stack, 'Invoke APIGW', { + api: restApi, + stageName: 'prod', + method: HttpMethod.GET, + authType: AuthType.IAM_ROLE, + outputPath: sfn.JsonPath.stringAt('$.ResponseBody'), +}); + +const chain = sfn.Chain.start(invokeJob); + +const sm = new sfn.StateMachine(stack, 'StateMachine', { + definition: chain, + timeout: cdk.Duration.seconds(30), +}); + +new cdk.CfnOutput(stack, 'stateMachineArn', { + value: sm.stateMachineArn, +}); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts new file mode 100644 index 0000000000000..c1e343f98852a --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts @@ -0,0 +1,131 @@ +import * as apigatewayv2 from '@aws-cdk/aws-apigatewayv2'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as cdk from '@aws-cdk/core'; +import { AuthType, HttpMethod, InvokeApiGatewayHttpApi } from '../../lib'; + +describe('InvokeApiGatewayHttpApi', () => { + test('default', () => { + // GIVEN + const stack = new cdk.Stack(); + const httpApi = new apigatewayv2.HttpApi(stack, 'HttpApi'); + + // WHEN + const task = new InvokeApiGatewayHttpApi(stack, 'Invoke', { + api: httpApi, + method: HttpMethod.GET, + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + End: true, + Parameters: { + ApiEndpoint: { + 'Fn::Join': [ + '', + [ + { + Ref: 'HttpApiF5A9A8A7', + }, + '.execute-api.', + { + Ref: 'AWS::Region', + }, + '.', + { + Ref: 'AWS::URLSuffix', + }, + ], + ], + }, + AuthType: 'NO_AUTH', + Method: 'GET', + }, + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::apigateway:invoke', + ], + ], + }, + }); + }); + + test('wait for task token', () => { + // GIVEN + const stack = new cdk.Stack(); + const httpApi = new apigatewayv2.HttpApi(stack, 'HttpApi'); + + // WHEN + const task = new InvokeApiGatewayHttpApi(stack, 'Invoke', { + api: httpApi, + method: HttpMethod.GET, + integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, + headers: sfn.TaskInput.fromObject({ TaskToken: sfn.JsonPath.taskToken }), + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + End: true, + Parameters: { + ApiEndpoint: { + 'Fn::Join': [ + '', + [ + { + Ref: 'HttpApiF5A9A8A7', + }, + '.execute-api.', + { + Ref: 'AWS::Region', + }, + '.', + { + Ref: 'AWS::URLSuffix', + }, + ], + ], + }, + AuthType: 'NO_AUTH', + Headers: { + 'TaskToken.$': '$$.Task.Token', + }, + Method: 'GET', + }, + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::apigateway:invoke.waitForTaskToken', + ], + ], + }, + }); + }); + + test('wait for task token - missing token', () => { + // GIVEN + const stack = new cdk.Stack(); + const httpApi = new apigatewayv2.HttpApi(stack, 'HttpApi'); + + // THEN + expect(() => { + new InvokeApiGatewayHttpApi(stack, 'Invoke', { + api: httpApi, + method: HttpMethod.GET, + integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, + authType: AuthType.RESOURCE_POLICY, + }); + }).toThrow('Task Token is required in `headers` Use JsonPath.taskToken to set the token.'); + }); +}); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts new file mode 100644 index 0000000000000..72eadb9b5a14d --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts @@ -0,0 +1,136 @@ +import * as apigateway from '@aws-cdk/aws-apigateway'; +import * as sfn from '@aws-cdk/aws-stepfunctions'; +import * as cdk from '@aws-cdk/core'; +import { AuthType, HttpMethod, InvokeApiGatewayRestApi } from '../../lib'; + +describe('InvokeApiGatewayRestApi', () => { + test('default', () => { + // GIVEN + const stack = new cdk.Stack(); + const restApi = new apigateway.RestApi(stack, 'RestApi'); + + // WHEN + const task = new InvokeApiGatewayRestApi(stack, 'Invoke', { + api: restApi, + method: HttpMethod.GET, + stageName: 'dev', + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + End: true, + Parameters: { + ApiEndpoint: { + 'Fn::Join': [ + '', + [ + { + Ref: 'RestApi0C43BF4B', + }, + '.execute-api.', + { + Ref: 'AWS::Region', + }, + '.', + { + Ref: 'AWS::URLSuffix', + }, + ], + ], + }, + AuthType: 'NO_AUTH', + Method: 'GET', + Stage: 'dev', + }, + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::apigateway:invoke', + ], + ], + }, + }); + }); + + test('wait for task token', () => { + // GIVEN + const stack = new cdk.Stack(); + const restApi = new apigateway.RestApi(stack, 'RestApi'); + + // WHEN + const task = new InvokeApiGatewayRestApi(stack, 'Invoke', { + api: restApi, + method: HttpMethod.GET, + stageName: 'dev', + integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, + headers: sfn.TaskInput.fromObject({ TaskToken: sfn.JsonPath.taskToken }), + }); + + // THEN + expect(stack.resolve(task.toStateJson())).toEqual({ + Type: 'Task', + End: true, + Parameters: { + ApiEndpoint: { + 'Fn::Join': [ + '', + [ + { + Ref: 'RestApi0C43BF4B', + }, + '.execute-api.', + { + Ref: 'AWS::Region', + }, + '.', + { + Ref: 'AWS::URLSuffix', + }, + ], + ], + }, + AuthType: 'NO_AUTH', + Headers: { + 'TaskToken.$': '$$.Task.Token', + }, + Method: 'GET', + Stage: 'dev', + }, + Resource: { + 'Fn::Join': [ + '', + [ + 'arn:', + { + Ref: 'AWS::Partition', + }, + ':states:::apigateway:invoke.waitForTaskToken', + ], + ], + }, + }); + }); + + test('wait for task token - missing token', () => { + // GIVEN + const stack = new cdk.Stack(); + const restApi = new apigateway.RestApi(stack, 'RestApi'); + + // THEN + expect(() => { + new InvokeApiGatewayRestApi(stack, 'Invoke', { + api: restApi, + method: HttpMethod.GET, + stageName: 'dev', + integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, + authType: AuthType.RESOURCE_POLICY, + }); + }).toThrow('Task Token is required in `headers` Use JsonPath.taskToken to set the token.'); + }); +}); From 9aff1babf52dd51491ac5666d70ed0bfdb731a29 Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Tue, 16 Feb 2021 21:32:42 +0530 Subject: [PATCH 2/8] fix typo --- .../@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts | 2 +- .../test/apigateway/integ.invoke-http-api.ts | 2 +- .../test/apigateway/integ.invoke-rest-api.ts | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts index 85b599af804a8..4afbaade3bbb4 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts @@ -151,4 +151,4 @@ export abstract class BaseInvokeApiGatewayApi extends sfn.TaskStateBase { } return []; } -} \ No newline at end of file +} diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts index f25b34218a52c..46f4126ed338e 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts @@ -10,7 +10,7 @@ import { AuthType, HttpMethod, InvokeApiGatewayHttpApi } from '../../lib'; * * aws stepfunctions start-execution --state-machine-arn : should return execution arn * * * aws stepfunctions describe-execution --execution-arn --query 'status': should return status as SUCCEEDED - * * aws stepfunctions describe-execution --execution-arn --query 'output': should return the number \"hello, world!\" + * * aws stepfunctions describe-execution --execution-arn --query 'output': should return the string \"hello, world!\" */ const app = new cdk.App(); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts index 70e2a4e84b647..cd4aada39117b 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts @@ -9,7 +9,7 @@ import { AuthType, HttpMethod, InvokeApiGatewayRestApi } from '../../lib'; * * aws stepfunctions start-execution --state-machine-arn : should return execution arn * * * aws stepfunctions describe-execution --execution-arn --query 'status': should return status as SUCCEEDED - * * aws stepfunctions describe-execution --execution-arn --query 'output': should return the number \"hello, world!\" + * * aws stepfunctions describe-execution --execution-arn --query 'output': should return the string \"hello, world!\" */ const app = new cdk.App(); From 9e12ae15e21c7977307f8b072075740436998c82 Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Sun, 28 Feb 2021 12:38:50 +0530 Subject: [PATCH 3/8] fix integ --- .../test/apigateway/integ.invoke-http-api.expected.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json index 0db21ee2251a2..6aabee2105d31 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json @@ -68,14 +68,14 @@ [ "integrations/", { - "Ref": "MyHttpApiHttpIntegration71abbf75d6f8e5ea93ec2120c0d78b75D3F1C5AA" + "Ref": "MyHttpApiANYHttpIntegration71abbf75d6f8e5ea93ec2120c0d78b754BBCECF5" } ] ] } } }, - "MyHttpApiHttpIntegration71abbf75d6f8e5ea93ec2120c0d78b75D3F1C5AA": { + "MyHttpApiANYHttpIntegration71abbf75d6f8e5ea93ec2120c0d78b754BBCECF5": { "Type": "AWS::ApiGatewayV2::Integration", "Properties": { "ApiId": { From f290780c29b5ab0f856c4d43aa6910b759ab9d85 Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Sun, 28 Feb 2021 14:18:36 +0530 Subject: [PATCH 4/8] do not export base class --- .../lib/apigateway/base-types.ts | 80 ++++++++++++++++++ .../lib/apigateway/{common.ts => base.ts} | 81 +------------------ .../lib/apigateway/index.ts | 2 +- .../lib/apigateway/invoke-http-api.ts | 3 +- .../lib/apigateway/invoke-rest-api.ts | 3 +- 5 files changed, 87 insertions(+), 82 deletions(-) create mode 100644 packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts rename packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/{common.ts => base.ts} (57%) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts new file mode 100644 index 0000000000000..78c94bf5f5b82 --- /dev/null +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts @@ -0,0 +1,80 @@ +import * as sfn from '@aws-cdk/aws-stepfunctions'; + +/** Http Methods that API Gateway supports */ +export enum HttpMethod { + /** Retreive data from a server at the specified resource */ + GET = 'GET', + + /** Send data to the API endpoint to create or udpate 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', + + /** Retreive data from a server at the specified resource without the response body */ + HEAD = 'HEAD', + + /** Return data describing what other methods and operations the server supports */ + OPTIONS = 'OPTIONS' +} + +/** + * The authentication method used to call the endpoint + */ +export enum AuthType { + /** Call the API direclty with no authorization method */ + NO_AUTH = 'NO_AUTH', + + /** * Use the IAM role associated with the current state machine for authorization */ + IAM_ROLE = 'IAM_ROLE', + + /** Use the resource policy of the API for authorization */ + RESOURCE_POLICY = 'RESOURCE_POLICY', +} + +/** + * Base ApiGateway Invoke Task Props + */ +export interface BaseInvokeApiGatewayApiProps extends sfn.TaskStateBaseProps { + /** + * Http method for the API + */ + readonly method: HttpMethod; + + /** + * HTTP request information that does not relate to contents of the request + * @default - No headers + */ + readonly headers?: sfn.TaskInput; + + + /** + * Path parameters appended after API endpoint + * @default - No path + */ + readonly path?: string; + + /** + * Query strings attatched to end of request + * @default - No query parameters + */ + readonly queryParameters?: sfn.TaskInput; + + /** + * HTTP Request body + * @default - No requestBody + */ + readonly requestBody?: sfn.TaskInput; + + /** + * Authentication methods + * @default AuthType.NO_AUTH + */ + readonly authType?: AuthType; +} diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts similarity index 57% rename from packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts rename to packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts index 4afbaade3bbb4..002daea3ea0ce 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/common.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts @@ -2,88 +2,11 @@ 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'; - -/** Http Methods that API Gateway supports */ -export enum HttpMethod { - /** Retreive data from a server at the specified resource */ - GET = 'GET', - - /** Send data to the API endpoint to create or udpate 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', - - /** Retreive data from a server at the specified resource without the response body */ - HEAD = 'HEAD', - - /** Return data describing what other methods and operations the server supports */ - OPTIONS = 'OPTIONS' -} - -/** - * The authentication method used to call the endpoint - */ -export enum AuthType { - /** Call the API direclty with no authorization method */ - NO_AUTH = 'NO_AUTH', - - /** * Use the IAM role associated with the current state machine for authorization */ - IAM_ROLE = 'IAM_ROLE', - - /** Use the resource policy of the API for authorization */ - RESOURCE_POLICY = 'RESOURCE_POLICY', -} - -/** - * Base ApiGateway Invoke Task Props - */ -export interface BaseInvokeApiGatewayApiProps extends sfn.TaskStateBaseProps { - /** - * Http method for the API - */ - readonly method: HttpMethod; - - /** - * HTTP request information that does not relate to contents of the request - * @default - No headers - */ - readonly headers?: sfn.TaskInput; - - - /** - * Path parameters appended after API endpoint - * @default - No path - */ - readonly path?: string; - - /** - * Query strings attatched to end of request - * @default - No query parameters - */ - readonly queryParameters?: sfn.TaskInput; - - /** - * HTTP Request body - * @default - No requestBody - */ - readonly requestBody?: sfn.TaskInput; - - /** - * Authentication methods - * @default AuthType.NO_AUTH - */ - readonly authType?: AuthType; -} +import { AuthType, BaseInvokeApiGatewayApiProps } from './base-types'; /** * Base ApiGateway Invoke Task + * @internal */ export abstract class BaseInvokeApiGatewayApi extends sfn.TaskStateBase { private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts index 364273a56e472..5bfc4d9fb94cc 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts @@ -1,3 +1,3 @@ -export * from './common'; +export * from './base-types'; export * from './invoke-rest-api'; export * from './invoke-http-api'; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts index a49d5c025c5e3..bc0459da92e9f 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts @@ -3,7 +3,8 @@ import * as iam from '@aws-cdk/aws-iam'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { BaseInvokeApiGatewayApi, BaseInvokeApiGatewayApiProps } from './common'; +import { BaseInvokeApiGatewayApi } from './base'; +import { BaseInvokeApiGatewayApiProps } from './base-types'; /** * Properties for invoking an HTTP API Endpoint diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts index 298d5b6775133..56b917323f50e 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts @@ -3,7 +3,8 @@ import * as iam from '@aws-cdk/aws-iam'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { BaseInvokeApiGatewayApi, BaseInvokeApiGatewayApiProps } from './common'; +import { BaseInvokeApiGatewayApi } from './base'; +import { BaseInvokeApiGatewayApiProps } from './base-types'; /** * Properties for invoking an REST API Endpoint From 82dcca3f2c71ecd0fce0ac2096b6097cb4e1b5d5 Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Thu, 4 Mar 2021 09:04:27 +0530 Subject: [PATCH 5/8] addressed comments --- .../aws-stepfunctions-tasks/README.md | 6 ++- .../lib/apigateway/base-types.ts | 9 ++-- .../lib/apigateway/base.ts | 50 ++++++++----------- .../lib/apigateway/invoke-http-api.ts | 12 ++--- .../lib/apigateway/invoke-rest-api.ts | 10 ++-- .../test/apigateway/invoke-http-api.test.ts | 20 ++++++-- .../test/apigateway/invoke-rest-api.test.ts | 21 ++++++-- 7 files changed, 76 insertions(+), 52 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/README.md b/packages/@aws-cdk/aws-stepfunctions-tasks/README.md index 31eb143e74307..2bbdebe7fa1d7 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/README.md +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/README.md @@ -220,7 +220,11 @@ of the Node.js family are supported. ## API Gateway -Step Functions support [API Gateway](https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html) through the service integration pattern. +Step Functions supports [API Gateway](https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html) through the service integration pattern. + +HTTP APIs are designed for low-latency, cost-effective integrations with AWS services, including AWS Lambda, and HTTP endpoints. +HTTP APIs support OIDC and OAuth 2.0 authorization, and come with built-in support for CORS and automatic deployments. +Previous-generation REST APIs currently offer more features. More details can be found [here](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html). ### Invoke REST API diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts index 78c94bf5f5b82..2aea74dd2f283 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts @@ -31,7 +31,7 @@ export enum AuthType { /** Call the API direclty with no authorization method */ NO_AUTH = 'NO_AUTH', - /** * Use the IAM role associated with the current state machine for authorization */ + /** Use the IAM role associated with the current state machine for authorization */ IAM_ROLE = 'IAM_ROLE', /** Use the resource policy of the API for authorization */ @@ -41,7 +41,7 @@ export enum AuthType { /** * Base ApiGateway Invoke Task Props */ -export interface BaseInvokeApiGatewayApiProps extends sfn.TaskStateBaseProps { +export interface InvokeApiGatewayApiBaseProps extends sfn.TaskStateBaseProps { /** * Http method for the API */ @@ -53,12 +53,11 @@ export interface BaseInvokeApiGatewayApiProps extends sfn.TaskStateBaseProps { */ readonly headers?: sfn.TaskInput; - /** * Path parameters appended after API endpoint * @default - No path */ - readonly path?: string; + readonly apiPath?: string; /** * Query strings attatched to end of request @@ -68,7 +67,7 @@ export interface BaseInvokeApiGatewayApiProps extends sfn.TaskStateBaseProps { /** * HTTP Request body - * @default - No requestBody + * @default - No request body */ readonly requestBody?: sfn.TaskInput; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts index 002daea3ea0ce..81519787835a6 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts @@ -2,31 +2,37 @@ 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'; -import { AuthType, BaseInvokeApiGatewayApiProps } from './base-types'; +import { AuthType, InvokeApiGatewayApiBaseProps } from './base-types'; /** * Base ApiGateway Invoke Task * @internal */ -export abstract class BaseInvokeApiGatewayApi extends sfn.TaskStateBase { +export abstract class InvokeApiGatewayApiBase extends sfn.TaskStateBase { private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ sfn.IntegrationPattern.REQUEST_RESPONSE, sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, ]; - private readonly baseProps: BaseInvokeApiGatewayApiProps; + private readonly baseProps: InvokeApiGatewayApiBaseProps; private readonly integrationPattern: sfn.IntegrationPattern; protected abstract readonly apiEndpoint: string; protected abstract readonly arnForExecuteApi: string; protected abstract readonly stageName?: string; - constructor(scope: Construct, id: string, props: BaseInvokeApiGatewayApiProps) { + constructor(scope: Construct, id: string, props: InvokeApiGatewayApiBaseProps) { super(scope, id, props); this.baseProps = props; this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE; - validatePatternSupported(this.integrationPattern, BaseInvokeApiGatewayApi.SUPPORTED_INTEGRATION_PATTERNS); + validatePatternSupported(this.integrationPattern, InvokeApiGatewayApiBase.SUPPORTED_INTEGRATION_PATTERNS); + + if (this.integrationPattern === sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN) { + if (!sfn.FieldUtils.containsTaskToken(this.baseProps.headers)) { + throw new Error('Task Token is required in `headers` for WAIT_FOR_TASK_TOKEN pattern. Use JsonPath.taskToken to set the token.'); + } + } } /** @@ -40,7 +46,7 @@ export abstract class BaseInvokeApiGatewayApi extends sfn.TaskStateBase { Method: this.baseProps.method, Headers: this.baseProps.headers?.value, Stage: this.stageName, - Path: this.baseProps.path, + Path: this.baseProps.apiPath, QueryParameters: this.baseProps.queryParameters?.value, RequestBody: this.baseProps.requestBody?.value, AuthType: this.baseProps.authType ? this.baseProps.authType : 'NO_AUTH', @@ -49,29 +55,15 @@ export abstract class BaseInvokeApiGatewayApi extends sfn.TaskStateBase { } protected createPolicyStatements(): iam.PolicyStatement[] { - if (this.baseProps.authType === AuthType.IAM_ROLE) { - return [ - new iam.PolicyStatement({ - resources: [this.arnForExecuteApi], - actions: ['ExecuteAPI:Invoke'], - }), - ]; - } else if (this.baseProps.authType === AuthType.RESOURCE_POLICY) { - if (!sfn.FieldUtils.containsTaskToken(this.baseProps.headers)) { - throw new Error('Task Token is required in `headers` Use JsonPath.taskToken to set the token.'); - } - return [ - new iam.PolicyStatement({ - resources: [this.arnForExecuteApi], - actions: ['ExecuteAPI:Invoke'], - conditions: { - StringEquals: { - 'aws:SourceArn': '*', - }, - }, - }), - ]; + if (this.baseProps.authType === AuthType.NO_AUTH) { + return []; } - return []; + + return [ + new iam.PolicyStatement({ + resources: [this.arnForExecuteApi], + actions: ['ExecuteAPI:Invoke'], + }), + ]; } } diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts index bc0459da92e9f..515ed7a7fba6a 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts @@ -3,13 +3,13 @@ import * as iam from '@aws-cdk/aws-iam'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { BaseInvokeApiGatewayApi } from './base'; -import { BaseInvokeApiGatewayApiProps } from './base-types'; +import { InvokeApiGatewayApiBase } from './base'; +import { InvokeApiGatewayApiBaseProps } from './base-types'; /** * Properties for invoking an HTTP API Endpoint */ -export interface InvokeApiGatewayHttpApiProps extends BaseInvokeApiGatewayApiProps { +export interface InvokeApiGatewayHttpApiProps extends InvokeApiGatewayApiBaseProps { /** * API to call */ @@ -27,7 +27,7 @@ export interface InvokeApiGatewayHttpApiProps extends BaseInvokeApiGatewayApiPro * * @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html */ -export class InvokeApiGatewayHttpApi extends BaseInvokeApiGatewayApi { +export class InvokeApiGatewayHttpApi extends InvokeApiGatewayApiBase { protected readonly taskMetrics?: sfn.TaskMetricsConfig | undefined; protected readonly taskPolicies?: iam.PolicyStatement[] | undefined; @@ -50,13 +50,13 @@ export class InvokeApiGatewayHttpApi extends BaseInvokeApiGatewayApi { } private getArnForExecuteApi(): string { - const { api, stageName, method, path } = this.props; + const { api, stageName, method, apiPath } = this.props; return cdk.Stack.of(api).formatArn({ service: 'execute-api', resource: api.httpApiId, sep: '/', - resourceName: `${stageName}/${method}${path}`, + resourceName: `${stageName}/${method}${apiPath}`, }); } } diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts index 56b917323f50e..5355afb857212 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts @@ -3,13 +3,13 @@ import * as iam from '@aws-cdk/aws-iam'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { BaseInvokeApiGatewayApi } from './base'; -import { BaseInvokeApiGatewayApiProps } from './base-types'; +import { InvokeApiGatewayApiBase } from './base'; +import { InvokeApiGatewayApiBaseProps } from './base-types'; /** * Properties for invoking an REST API Endpoint */ -export interface InvokeApiGatewayRestApiProps extends BaseInvokeApiGatewayApiProps { +export interface InvokeApiGatewayRestApiProps extends InvokeApiGatewayApiBaseProps { /** * API to call */ @@ -26,7 +26,7 @@ export interface InvokeApiGatewayRestApiProps extends BaseInvokeApiGatewayApiPro * * @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html */ -export class InvokeApiGatewayRestApi extends BaseInvokeApiGatewayApi { +export class InvokeApiGatewayRestApi extends InvokeApiGatewayApiBase { protected readonly taskMetrics?: sfn.TaskMetricsConfig | undefined; protected readonly taskPolicies?: iam.PolicyStatement[] | undefined; @@ -38,7 +38,7 @@ export class InvokeApiGatewayRestApi extends BaseInvokeApiGatewayApi { super(scope, id, props); this.apiEndpoint = this.getApiEndpoint(); - this.arnForExecuteApi = props.api.arnForExecuteApi(props.method, props.path, props.stageName); + this.arnForExecuteApi = props.api.arnForExecuteApi(props.method, props.apiPath, props.stageName); this.stageName = props.stageName; this.taskPolicies = this.createPolicyStatements(); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts index c1e343f98852a..5640accd15b32 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts @@ -1,7 +1,7 @@ import * as apigatewayv2 from '@aws-cdk/aws-apigatewayv2'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; -import { AuthType, HttpMethod, InvokeApiGatewayHttpApi } from '../../lib'; +import { HttpMethod, InvokeApiGatewayHttpApi } from '../../lib'; describe('InvokeApiGatewayHttpApi', () => { test('default', () => { @@ -124,8 +124,22 @@ describe('InvokeApiGatewayHttpApi', () => { api: httpApi, method: HttpMethod.GET, integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, - authType: AuthType.RESOURCE_POLICY, }); - }).toThrow('Task Token is required in `headers` Use JsonPath.taskToken to set the token.'); + }).toThrow(/Task Token is required in `headers` for WAIT_FOR_TASK_TOKEN pattern. Use JsonPath.taskToken to set the token./); + }); + + test('unsupported integration pattern - RUN_JOB', () => { + // GIVEN + const stack = new cdk.Stack(); + const httpApi = new apigatewayv2.HttpApi(stack, 'HttpApi'); + + // THEN + expect(() => { + new InvokeApiGatewayHttpApi(stack, 'Invoke', { + api: httpApi, + method: HttpMethod.GET, + integrationPattern: sfn.IntegrationPattern.RUN_JOB, + }); + }).toThrow(/Unsupported service integration pattern./); }); }); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts index 72eadb9b5a14d..83fcd5be6a264 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts @@ -1,7 +1,7 @@ import * as apigateway from '@aws-cdk/aws-apigateway'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; -import { AuthType, HttpMethod, InvokeApiGatewayRestApi } from '../../lib'; +import { HttpMethod, InvokeApiGatewayRestApi } from '../../lib'; describe('InvokeApiGatewayRestApi', () => { test('default', () => { @@ -129,8 +129,23 @@ describe('InvokeApiGatewayRestApi', () => { method: HttpMethod.GET, stageName: 'dev', integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, - authType: AuthType.RESOURCE_POLICY, }); - }).toThrow('Task Token is required in `headers` Use JsonPath.taskToken to set the token.'); + }).toThrow(/Task Token is required in `headers` for WAIT_FOR_TASK_TOKEN pattern. Use JsonPath.taskToken to set the token./); + }); + + test('unsupported integration pattern - RUN_JOB', () => { + // GIVEN + const stack = new cdk.Stack(); + const restApi = new apigateway.RestApi(stack, 'RestApi'); + + // THEN + expect(() => { + new InvokeApiGatewayRestApi(stack, 'Invoke', { + api: restApi, + method: HttpMethod.GET, + stageName: 'dev', + integrationPattern: sfn.IntegrationPattern.RUN_JOB, + }); + }).toThrow(/Unsupported service integration pattern./); }); }); From 29d4b91fd93426a03acbfb4265e5244798cb443d Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Fri, 5 Mar 2021 08:24:15 +0530 Subject: [PATCH 6/8] fix an action typo --- .../lib/apigateway/base.ts | 2 +- .../integ.invoke-http-api.expected.json | 34 +++++++++---------- .../integ.invoke-rest-api.expected.json | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts index 81519787835a6..69976df596e2f 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts @@ -62,7 +62,7 @@ export abstract class InvokeApiGatewayApiBase extends sfn.TaskStateBase { return [ new iam.PolicyStatement({ resources: [this.arnForExecuteApi], - actions: ['ExecuteAPI:Invoke'], + actions: ['execute-api:Invoke'], }), ]; } diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json index 6aabee2105d31..abd512e779451 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json @@ -54,6 +54,22 @@ } } }, + "MyHttpApiANYHttpIntegration71abbf75d6f8e5ea93ec2120c0d78b754BBCECF5": { + "Type": "AWS::ApiGatewayV2::Integration", + "Properties": { + "ApiId": { + "Ref": "MyHttpApi8AEAAC21" + }, + "IntegrationType": "AWS_PROXY", + "IntegrationUri": { + "Fn::GetAtt": [ + "HelloHandler2E4FBA4D", + "Arn" + ] + }, + "PayloadFormatVersion": "2.0" + } + }, "MyHttpApiANYC3543576": { "Type": "AWS::ApiGatewayV2::Route", "Properties": { @@ -75,22 +91,6 @@ } } }, - "MyHttpApiANYHttpIntegration71abbf75d6f8e5ea93ec2120c0d78b754BBCECF5": { - "Type": "AWS::ApiGatewayV2::Integration", - "Properties": { - "ApiId": { - "Ref": "MyHttpApi8AEAAC21" - }, - "IntegrationType": "AWS_PROXY", - "IntegrationUri": { - "Fn::GetAtt": [ - "HelloHandler2E4FBA4D", - "Arn" - ] - }, - "PayloadFormatVersion": "2.0" - } - }, "HelloHandlerServiceRole11EF7C63": { "Type": "AWS::IAM::Role", "Properties": { @@ -175,7 +175,7 @@ "PolicyDocument": { "Statement": [ { - "Action": "ExecuteAPI:Invoke", + "Action": "execute-api:Invoke", "Effect": "Allow", "Resource": { "Fn::Join": [ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json index c5f0305d25485..fe7d6e2c8d2cd 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json @@ -280,7 +280,7 @@ "PolicyDocument": { "Statement": [ { - "Action": "ExecuteAPI:Invoke", + "Action": "execute-api:Invoke", "Effect": "Allow", "Resource": { "Fn::Join": [ From ad58f09ffee648d68bbcb283820e533bf0b12a15 Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Fri, 5 Mar 2021 21:58:09 +0530 Subject: [PATCH 7/8] fix depcrecated api --- .../aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts index 515ed7a7fba6a..42fe6365ffe35 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts @@ -46,7 +46,7 @@ export class InvokeApiGatewayHttpApi extends InvokeApiGatewayApiBase { private getApiEndpoint(): string { const apiStack = cdk.Stack.of(this.props.api); - return `${this.props.api.httpApiId}.execute-api.${apiStack.region}.${apiStack.urlSuffix}`; + return `${this.props.api.apiId}.execute-api.${apiStack.region}.${apiStack.urlSuffix}`; } private getArnForExecuteApi(): string { @@ -54,7 +54,7 @@ export class InvokeApiGatewayHttpApi extends InvokeApiGatewayApiBase { return cdk.Stack.of(api).formatArn({ service: 'execute-api', - resource: api.httpApiId, + resource: api.apiId, sep: '/', resourceName: `${stageName}/${method}${apiPath}`, }); From ec3ae0485ea90f6d52291109d3477346a7bf0bd1 Mon Sep 17 00:00:00 2001 From: Ayush Goyal Date: Tue, 9 Mar 2021 10:21:58 +0530 Subject: [PATCH 8/8] rename invoke to call --- .../@aws-cdk/aws-stepfunctions-tasks/README.md | 16 ++++++++-------- .../lib/apigateway/base-types.ts | 4 ++-- .../lib/apigateway/base.ts | 12 ++++++------ .../{invoke-http-api.ts => call-http-api.ts} | 14 +++++++------- .../{invoke-rest-api.ts => call-rest-api.ts} | 14 +++++++------- .../lib/apigateway/index.ts | 4 ++-- ...ke-http-api.test.ts => call-http-api.test.ts} | 12 ++++++------ ...ke-rest-api.test.ts => call-rest-api.test.ts} | 12 ++++++------ ...ed.json => integ.call-http-api.expected.json} | 4 ++-- ...invoke-http-api.ts => integ.call-http-api.ts} | 8 ++++---- ...ed.json => integ.call-rest-api.expected.json} | 6 +++--- ...invoke-rest-api.ts => integ.call-rest-api.ts} | 8 ++++---- 12 files changed, 57 insertions(+), 57 deletions(-) rename packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/{invoke-http-api.ts => call-http-api.ts} (78%) rename packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/{invoke-rest-api.ts => call-rest-api.ts} (75%) rename packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/{invoke-http-api.test.ts => call-http-api.test.ts} (89%) rename packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/{invoke-rest-api.test.ts => call-rest-api.test.ts} (90%) rename packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/{integ.invoke-http-api.expected.json => integ.call-http-api.expected.json} (96%) rename packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/{integ.invoke-http-api.ts => integ.call-http-api.ts} (85%) rename packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/{integ.invoke-rest-api.expected.json => integ.call-rest-api.expected.json} (96%) rename packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/{integ.invoke-rest-api.ts => integ.call-rest-api.ts} (84%) diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/README.md b/packages/@aws-cdk/aws-stepfunctions-tasks/README.md index 2bbdebe7fa1d7..2277b0e14416b 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/README.md +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/README.md @@ -29,8 +29,8 @@ This module is part of the [AWS Cloud Development Kit](https://github.com/aws/aw - [Parameters](#task-parameters-from-the-state-json) - [Evaluate Expression](#evaluate-expression) - [API Gateway](#api-gateway) - - [InvokeRestApi](#invoke-rest-api) - - [InvokeHttpApi](#invoke-http-api) + - [Call REST API Endpoint](#call-rest-api-endpoint) + - [Call HTTP API Endpoint](#call-http-api-endpoint) - [Athena](#athena) - [StartQueryExecution](#startQueryExecution) - [GetQueryExecution](#getQueryExecution) @@ -226,9 +226,9 @@ HTTP APIs are designed for low-latency, cost-effective integrations with AWS ser HTTP APIs support OIDC and OAuth 2.0 authorization, and come with built-in support for CORS and automatic deployments. Previous-generation REST APIs currently offer more features. More details can be found [here](https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-vs-rest.html). -### Invoke REST API +### Call REST API Endpoint -The `InvokeApiGatewayRestApi` calls the REST API endpoint. +The `CallApiGatewayRestApiEndpoint` calls the REST API endpoint. ```ts import * as sfn from '@aws-cdk/aws-stepfunctions'; @@ -236,16 +236,16 @@ import * as tasks from `@aws-cdk/aws-stepfunctions-tasks`; const restApi = new apigateway.RestApi(stack, 'MyRestApi'); -const invokeTask = new tasks.InvokeApiGatewayRestApi(stack, 'Invoke REST API', { +const invokeTask = new tasks.CallApiGatewayRestApiEndpoint(stack, 'Call REST API', { api: restApi, stageName: 'prod', method: HttpMethod.GET, }); ``` -### Invoke HTTP API +### Call HTTP API Endpoint -The `InvokeApiGatewayHttpApi` calls the HTTP API endpoint. +The `CallApiGatewayHttpApiEndpoint` calls the HTTP API endpoint. ```ts import * as sfn from '@aws-cdk/aws-stepfunctions'; @@ -253,7 +253,7 @@ import * as tasks from `@aws-cdk/aws-stepfunctions-tasks`; const httpApi = new apigatewayv2.HttpApi(stack, 'MyHttpApi'); -const invokeTask = new tasks.InvokeApiGatewayHttpApi(stack, 'Invoke HTTP API', { +const invokeTask = new tasks.CallApiGatewayHttpApiEndpoint(stack, 'Call HTTP API', { api: httpApi, method: HttpMethod.GET, }); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts index 2aea74dd2f283..64c649063e57c 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base-types.ts @@ -39,9 +39,9 @@ export enum AuthType { } /** - * Base ApiGateway Invoke Task Props + * Base CallApiGatewayEdnpoint Task Props */ -export interface InvokeApiGatewayApiBaseProps extends sfn.TaskStateBaseProps { +export interface CallApiGatewayEndpointBaseProps extends sfn.TaskStateBaseProps { /** * Http method for the API */ diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts index 69976df596e2f..edce3aa0f627c 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/base.ts @@ -2,31 +2,31 @@ 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'; -import { AuthType, InvokeApiGatewayApiBaseProps } from './base-types'; +import { AuthType, CallApiGatewayEndpointBaseProps } from './base-types'; /** - * Base ApiGateway Invoke Task + * Base CallApiGatewayEndpoint Task * @internal */ -export abstract class InvokeApiGatewayApiBase extends sfn.TaskStateBase { +export abstract class CallApiGatewayEndpointBase extends sfn.TaskStateBase { private static readonly SUPPORTED_INTEGRATION_PATTERNS: sfn.IntegrationPattern[] = [ sfn.IntegrationPattern.REQUEST_RESPONSE, sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, ]; - private readonly baseProps: InvokeApiGatewayApiBaseProps; + private readonly baseProps: CallApiGatewayEndpointBaseProps; private readonly integrationPattern: sfn.IntegrationPattern; protected abstract readonly apiEndpoint: string; protected abstract readonly arnForExecuteApi: string; protected abstract readonly stageName?: string; - constructor(scope: Construct, id: string, props: InvokeApiGatewayApiBaseProps) { + constructor(scope: Construct, id: string, props: CallApiGatewayEndpointBaseProps) { super(scope, id, props); this.baseProps = props; this.integrationPattern = props.integrationPattern ?? sfn.IntegrationPattern.REQUEST_RESPONSE; - validatePatternSupported(this.integrationPattern, InvokeApiGatewayApiBase.SUPPORTED_INTEGRATION_PATTERNS); + validatePatternSupported(this.integrationPattern, CallApiGatewayEndpointBase.SUPPORTED_INTEGRATION_PATTERNS); if (this.integrationPattern === sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN) { if (!sfn.FieldUtils.containsTaskToken(this.baseProps.headers)) { diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/call-http-api.ts similarity index 78% rename from packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts rename to packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/call-http-api.ts index 42fe6365ffe35..e06e46c2580b0 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-http-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/call-http-api.ts @@ -3,13 +3,13 @@ import * as iam from '@aws-cdk/aws-iam'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { InvokeApiGatewayApiBase } from './base'; -import { InvokeApiGatewayApiBaseProps } from './base-types'; +import { CallApiGatewayEndpointBase } from './base'; +import { CallApiGatewayEndpointBaseProps } from './base-types'; /** - * Properties for invoking an HTTP API Endpoint + * Properties for calling an HTTP API Endpoint */ -export interface InvokeApiGatewayHttpApiProps extends InvokeApiGatewayApiBaseProps { +export interface CallApiGatewayHttpApiEndpointProps extends CallApiGatewayEndpointBaseProps { /** * API to call */ @@ -23,11 +23,11 @@ export interface InvokeApiGatewayHttpApiProps extends InvokeApiGatewayApiBasePro } /** - * Invoke HTTP API endpoint as a Task + * Call HTTP API endpoint as a Task * * @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html */ -export class InvokeApiGatewayHttpApi extends InvokeApiGatewayApiBase { +export class CallApiGatewayHttpApiEndpoint extends CallApiGatewayEndpointBase { protected readonly taskMetrics?: sfn.TaskMetricsConfig | undefined; protected readonly taskPolicies?: iam.PolicyStatement[] | undefined; @@ -35,7 +35,7 @@ export class InvokeApiGatewayHttpApi extends InvokeApiGatewayApiBase { protected readonly arnForExecuteApi: string; protected readonly stageName?: string; - constructor(scope: Construct, id: string, private readonly props: InvokeApiGatewayHttpApiProps) { + constructor(scope: Construct, id: string, private readonly props: CallApiGatewayHttpApiEndpointProps) { super(scope, id, props); this.apiEndpoint = this.getApiEndpoint(); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts similarity index 75% rename from packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts rename to packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts index 5355afb857212..0352777e9c06a 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/invoke-rest-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/call-rest-api.ts @@ -3,13 +3,13 @@ import * as iam from '@aws-cdk/aws-iam'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; import { Construct } from 'constructs'; -import { InvokeApiGatewayApiBase } from './base'; -import { InvokeApiGatewayApiBaseProps } from './base-types'; +import { CallApiGatewayEndpointBase } from './base'; +import { CallApiGatewayEndpointBaseProps } from './base-types'; /** - * Properties for invoking an REST API Endpoint + * Properties for calling an REST API Endpoint */ -export interface InvokeApiGatewayRestApiProps extends InvokeApiGatewayApiBaseProps { +export interface CallApiGatewayRestApiEndpointProps extends CallApiGatewayEndpointBaseProps { /** * API to call */ @@ -22,11 +22,11 @@ export interface InvokeApiGatewayRestApiProps extends InvokeApiGatewayApiBasePro } /** - * Invoke REST API endpoint as a Task + * Call REST API endpoint as a Task * * @see https://docs.aws.amazon.com/step-functions/latest/dg/connect-api-gateway.html */ -export class InvokeApiGatewayRestApi extends InvokeApiGatewayApiBase { +export class CallApiGatewayRestApiEndpoint extends CallApiGatewayEndpointBase { protected readonly taskMetrics?: sfn.TaskMetricsConfig | undefined; protected readonly taskPolicies?: iam.PolicyStatement[] | undefined; @@ -34,7 +34,7 @@ export class InvokeApiGatewayRestApi extends InvokeApiGatewayApiBase { protected readonly arnForExecuteApi: string; protected readonly stageName?: string; - constructor(scope: Construct, id: string, private readonly props: InvokeApiGatewayRestApiProps) { + constructor(scope: Construct, id: string, private readonly props: CallApiGatewayRestApiEndpointProps) { super(scope, id, props); this.apiEndpoint = this.getApiEndpoint(); diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts index 5bfc4d9fb94cc..3d82ca2e7d548 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/lib/apigateway/index.ts @@ -1,3 +1,3 @@ export * from './base-types'; -export * from './invoke-rest-api'; -export * from './invoke-http-api'; +export * from './call-rest-api'; +export * from './call-http-api'; diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/call-http-api.test.ts similarity index 89% rename from packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts rename to packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/call-http-api.test.ts index 5640accd15b32..0e7a2cf616b9a 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-http-api.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/call-http-api.test.ts @@ -1,16 +1,16 @@ import * as apigatewayv2 from '@aws-cdk/aws-apigatewayv2'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; -import { HttpMethod, InvokeApiGatewayHttpApi } from '../../lib'; +import { HttpMethod, CallApiGatewayHttpApiEndpoint } from '../../lib'; -describe('InvokeApiGatewayHttpApi', () => { +describe('CallApiGatewayHttpApiEndpoint', () => { test('default', () => { // GIVEN const stack = new cdk.Stack(); const httpApi = new apigatewayv2.HttpApi(stack, 'HttpApi'); // WHEN - const task = new InvokeApiGatewayHttpApi(stack, 'Invoke', { + const task = new CallApiGatewayHttpApiEndpoint(stack, 'Call', { api: httpApi, method: HttpMethod.GET, }); @@ -62,7 +62,7 @@ describe('InvokeApiGatewayHttpApi', () => { const httpApi = new apigatewayv2.HttpApi(stack, 'HttpApi'); // WHEN - const task = new InvokeApiGatewayHttpApi(stack, 'Invoke', { + const task = new CallApiGatewayHttpApiEndpoint(stack, 'Call', { api: httpApi, method: HttpMethod.GET, integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, @@ -120,7 +120,7 @@ describe('InvokeApiGatewayHttpApi', () => { // THEN expect(() => { - new InvokeApiGatewayHttpApi(stack, 'Invoke', { + new CallApiGatewayHttpApiEndpoint(stack, 'Call', { api: httpApi, method: HttpMethod.GET, integrationPattern: sfn.IntegrationPattern.WAIT_FOR_TASK_TOKEN, @@ -135,7 +135,7 @@ describe('InvokeApiGatewayHttpApi', () => { // THEN expect(() => { - new InvokeApiGatewayHttpApi(stack, 'Invoke', { + new CallApiGatewayHttpApiEndpoint(stack, 'Call', { api: httpApi, method: HttpMethod.GET, integrationPattern: sfn.IntegrationPattern.RUN_JOB, diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts similarity index 90% rename from packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts rename to packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts index 83fcd5be6a264..37a083fb2cc95 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/invoke-rest-api.test.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/call-rest-api.test.ts @@ -1,16 +1,16 @@ import * as apigateway from '@aws-cdk/aws-apigateway'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; -import { HttpMethod, InvokeApiGatewayRestApi } from '../../lib'; +import { HttpMethod, CallApiGatewayRestApiEndpoint } from '../../lib'; -describe('InvokeApiGatewayRestApi', () => { +describe('CallApiGatewayRestApiEndpoint', () => { test('default', () => { // GIVEN const stack = new cdk.Stack(); const restApi = new apigateway.RestApi(stack, 'RestApi'); // WHEN - const task = new InvokeApiGatewayRestApi(stack, 'Invoke', { + const task = new CallApiGatewayRestApiEndpoint(stack, 'Call', { api: restApi, method: HttpMethod.GET, stageName: 'dev', @@ -64,7 +64,7 @@ describe('InvokeApiGatewayRestApi', () => { const restApi = new apigateway.RestApi(stack, 'RestApi'); // WHEN - const task = new InvokeApiGatewayRestApi(stack, 'Invoke', { + const task = new CallApiGatewayRestApiEndpoint(stack, 'Call', { api: restApi, method: HttpMethod.GET, stageName: 'dev', @@ -124,7 +124,7 @@ describe('InvokeApiGatewayRestApi', () => { // THEN expect(() => { - new InvokeApiGatewayRestApi(stack, 'Invoke', { + new CallApiGatewayRestApiEndpoint(stack, 'Call', { api: restApi, method: HttpMethod.GET, stageName: 'dev', @@ -140,7 +140,7 @@ describe('InvokeApiGatewayRestApi', () => { // THEN expect(() => { - new InvokeApiGatewayRestApi(stack, 'Invoke', { + new CallApiGatewayRestApiEndpoint(stack, 'Call', { api: restApi, method: HttpMethod.GET, stageName: 'dev', diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-http-api.expected.json similarity index 96% rename from packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json rename to packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-http-api.expected.json index abd512e779451..6afe44cfecda5 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-http-api.expected.json @@ -17,7 +17,7 @@ "AutoDeploy": true } }, - "MyHttpApiANYInvokeHttpApiIntegMyHttpApiANY146E68A6PermissionAB056FD4": { + "MyHttpApiANYCallHttpApiIntegMyHttpApiANY7E6F12A3Permission59116CA6": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -226,7 +226,7 @@ "Fn::Join": [ "", [ - "{\"StartAt\":\"Invoke APIGW\",\"States\":{\"Invoke APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", + "{\"StartAt\":\"Call APIGW\",\"States\":{\"Call APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", { "Ref": "AWS::Partition" }, diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-http-api.ts similarity index 85% rename from packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts rename to packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-http-api.ts index 46f4126ed338e..4eb1f3b896e92 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-http-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-http-api.ts @@ -3,7 +3,7 @@ import * as integrations from '@aws-cdk/aws-apigatewayv2-integrations'; import * as lambda from '@aws-cdk/aws-lambda'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; -import { AuthType, HttpMethod, InvokeApiGatewayHttpApi } from '../../lib'; +import { AuthType, HttpMethod, CallApiGatewayHttpApiEndpoint } from '../../lib'; /* * Stack verification steps: @@ -14,7 +14,7 @@ import { AuthType, HttpMethod, InvokeApiGatewayHttpApi } from '../../lib'; */ const app = new cdk.App(); -const stack = new cdk.Stack(app, 'InvokeHttpApiInteg'); +const stack = new cdk.Stack(app, 'CallHttpApiInteg'); const httpApi = new apigatewayv2.HttpApi(stack, 'MyHttpApi'); const handler = new lambda.Function(stack, 'HelloHandler', { @@ -29,14 +29,14 @@ httpApi.addRoutes({ }), }); -const invokeJob = new InvokeApiGatewayHttpApi(stack, 'Invoke APIGW', { +const callEndpointJob = new CallApiGatewayHttpApiEndpoint(stack, 'Call APIGW', { api: httpApi, method: HttpMethod.GET, authType: AuthType.IAM_ROLE, outputPath: sfn.JsonPath.stringAt('$.ResponseBody'), }); -const chain = sfn.Chain.start(invokeJob); +const chain = sfn.Chain.start(callEndpointJob); const sm = new sfn.StateMachine(stack, 'StateMachine', { definition: chain, diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api.expected.json similarity index 96% rename from packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json rename to packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api.expected.json index fe7d6e2c8d2cd..5970499935354 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.expected.json +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api.expected.json @@ -75,7 +75,7 @@ "StageName": "prod" } }, - "MyRestApiANYApiPermissionInvokeRestApiIntegMyRestApi9DA14B28ANY5B4931EE": { + "MyRestApiANYApiPermissionCallRestApiIntegMyRestApiB570839CANY0C27C1E3": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -116,7 +116,7 @@ } } }, - "MyRestApiANYApiPermissionTestInvokeRestApiIntegMyRestApi9DA14B28ANY922900DE": { + "MyRestApiANYApiPermissionTestCallRestApiIntegMyRestApiB570839CANY379723EF": { "Type": "AWS::Lambda::Permission", "Properties": { "Action": "lambda:InvokeFunction", @@ -331,7 +331,7 @@ "Fn::Join": [ "", [ - "{\"StartAt\":\"Invoke APIGW\",\"States\":{\"Invoke APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", + "{\"StartAt\":\"Call APIGW\",\"States\":{\"Call APIGW\":{\"End\":true,\"Type\":\"Task\",\"OutputPath\":\"$.ResponseBody\",\"Resource\":\"arn:", { "Ref": "AWS::Partition" }, diff --git a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api.ts similarity index 84% rename from packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts rename to packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api.ts index cd4aada39117b..7cfe3c85ab12b 100644 --- a/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.invoke-rest-api.ts +++ b/packages/@aws-cdk/aws-stepfunctions-tasks/test/apigateway/integ.call-rest-api.ts @@ -2,7 +2,7 @@ import * as apigateway from '@aws-cdk/aws-apigateway'; import * as lambda from '@aws-cdk/aws-lambda'; import * as sfn from '@aws-cdk/aws-stepfunctions'; import * as cdk from '@aws-cdk/core'; -import { AuthType, HttpMethod, InvokeApiGatewayRestApi } from '../../lib'; +import { AuthType, HttpMethod, CallApiGatewayRestApiEndpoint } from '../../lib'; /* * Stack verification steps: @@ -13,7 +13,7 @@ import { AuthType, HttpMethod, InvokeApiGatewayRestApi } from '../../lib'; */ const app = new cdk.App(); -const stack = new cdk.Stack(app, 'InvokeRestApiInteg'); +const stack = new cdk.Stack(app, 'CallRestApiInteg'); const restApi = new apigateway.RestApi(stack, 'MyRestApi'); const hello = new apigateway.LambdaIntegration(new lambda.Function(stack, 'Hello', { @@ -23,7 +23,7 @@ const hello = new apigateway.LambdaIntegration(new lambda.Function(stack, 'Hello })); restApi.root.addMethod('ANY', hello); -const invokeJob = new InvokeApiGatewayRestApi(stack, 'Invoke APIGW', { +const callEndpointJob = new CallApiGatewayRestApiEndpoint(stack, 'Call APIGW', { api: restApi, stageName: 'prod', method: HttpMethod.GET, @@ -31,7 +31,7 @@ const invokeJob = new InvokeApiGatewayRestApi(stack, 'Invoke APIGW', { outputPath: sfn.JsonPath.stringAt('$.ResponseBody'), }); -const chain = sfn.Chain.start(invokeJob); +const chain = sfn.Chain.start(callEndpointJob); const sm = new sfn.StateMachine(stack, 'StateMachine', { definition: chain,