Skip to content

Commit dfc6665

Browse files
unstubbableElad Ben-Israel
authored andcommitted
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
1 parent 9f88696 commit dfc6665

File tree

2 files changed

+30
-1
lines changed

2 files changed

+30
-1
lines changed

packages/@aws-cdk/aws-apigateway/lib/integrations/aws.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,13 @@ export interface AwsIntegrationProps {
4949
*/
5050
readonly actionParameters?: { [key: string]: string };
5151

52+
/**
53+
* The integration's HTTP method type.
54+
*
55+
* @default POST
56+
*/
57+
readonly integrationHttpMethod?: string;
58+
5259
/**
5360
* Integration options, such as content handling, request/response mapping, etc.
5461
*/
@@ -70,7 +77,7 @@ export class AwsIntegration extends Integration {
7077
const { apiType, apiValue } = parseAwsApiCall(props.path, props.action, props.actionParameters);
7178
super({
7279
type,
73-
integrationHttpMethod: 'POST',
80+
integrationHttpMethod: props.integrationHttpMethod || 'POST',
7481
uri: new cdk.Token(() => {
7582
if (!this.scope) { throw new Error('AwsIntegration must be used in API'); }
7683
return this.scope.node.stack.formatArn({

packages/@aws-cdk/aws-apigateway/test/test.method.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,28 @@ export = {
8787
test.done();
8888
},
8989

90+
'integration with a custom http method can be set via a property'(test: Test) {
91+
// GIVEN
92+
const stack = new cdk.Stack();
93+
const api = new apigateway.RestApi(stack, 'test-api', { cloudWatchRole: false, deploy: false });
94+
95+
// WHEN
96+
new apigateway.Method(stack, 'my-method', {
97+
httpMethod: 'POST',
98+
resource: api.root,
99+
integration: new apigateway.AwsIntegration({ service: 's3', path: 'bucket/key', integrationHttpMethod: 'GET' })
100+
});
101+
102+
// THEN
103+
expect(stack).to(haveResourceLike('AWS::ApiGateway::Method', {
104+
Integration: {
105+
IntegrationHttpMethod: "GET"
106+
}
107+
}));
108+
109+
test.done();
110+
},
111+
90112
'use default integration from api'(test: Test) {
91113
// GIVEN
92114
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)