Skip to content

Commit

Permalink
fix(aws-apigateway): add integrationHttpMethod prop to AwsIntegration
Browse files Browse the repository at this point in the history
Allows a custom http method to be used for an AWS integration, using POST as default.

Fixes #2105
  • Loading branch information
unstubbable committed Apr 3, 2019
1 parent 2e92d44 commit 9d50dcd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*/
Expand All @@ -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({
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.method.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 9d50dcd

Please sign in to comment.