From dfc666523ec3e552bcb80207298a51f3df490c4b Mon Sep 17 00:00:00 2001 From: Hendrik Liebau Date: Wed, 10 Apr 2019 11:51:24 +0200 Subject: [PATCH] fix(aws-apigateway): add integrationHttpMethod prop to AwsIntegration (#2160) Allows a custom http method to be used for an AWS integration, using POST as default. Fixes #2105 --- .../aws-apigateway/lib/integrations/aws.ts | 9 +++++++- .../aws-apigateway/test/test.method.ts | 22 +++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts b/packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts index 5dd0c2584e85c..8ccb4d11cc654 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts @@ -49,6 +49,13 @@ export interface AwsIntegrationProps { */ readonly actionParameters?: { [key: string]: string }; + /** + * The integration's HTTP method type. + * + * @default POST + */ + readonly integrationHttpMethod?: string; + /** * Integration options, such as content handling, request/response mapping, etc. */ @@ -70,7 +77,7 @@ export class AwsIntegration extends Integration { const { apiType, apiValue } = parseAwsApiCall(props.path, props.action, props.actionParameters); super({ type, - integrationHttpMethod: 'POST', + integrationHttpMethod: props.integrationHttpMethod || 'POST', uri: new cdk.Token(() => { if (!this.scope) { throw new Error('AwsIntegration must be used in API'); } return this.scope.node.stack.formatArn({ diff --git a/packages/@aws-cdk/aws-apigateway/test/test.method.ts b/packages/@aws-cdk/aws-apigateway/test/test.method.ts index b74b6f1241baf..d1d2919ee28f0 100644 --- a/packages/@aws-cdk/aws-apigateway/test/test.method.ts +++ b/packages/@aws-cdk/aws-apigateway/test/test.method.ts @@ -87,6 +87,28 @@ export = { test.done(); }, + 'integration with a custom http method can be set via a property'(test: Test) { + // GIVEN + const stack = new cdk.Stack(); + const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: false }); + + // WHEN + new apigateway.Method(stack, 'my-method', { + httpMethod: 'POST', + resource: api.root, + integration: new apigateway.AwsIntegration({ service: 's3', path: 'bucket/key', integrationHttpMethod: 'GET' }) + }); + + // THEN + expect(stack).to(haveResourceLike('AWS::ApiGateway::Method', { + Integration: { + IntegrationHttpMethod: "GET" + } + })); + + test.done(); + }, + 'use default integration from api'(test: Test) { // GIVEN const stack = new cdk.Stack();