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 aws#2105
  • Loading branch information
unstubbable committed Apr 2, 2019
1 parent 2e92d44 commit dc8a688
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 9 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,14 @@ export interface AwsIntegrationProps {
*/
readonly actionParameters?: { [key: string]: string };

/**
* The integration's HTTP method type.
* Required unless you use a MOCK integration.
*
* @default POST
*/
readonly integrationHttpMethod?: string;

/**
* Integration options, such as content handling, request/response mapping, etc.
*/
Expand All @@ -70,7 +78,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
32 changes: 32 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,38 @@ 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(haveResource('AWS::ApiGateway::Method', {
Integration: {
IntegrationHttpMethod: "GET",
Type: "AWS",
Uri: {
"Fn::Join": [
"",
[
"arn:", { Ref: "AWS::Partition" }, ":apigateway:",
{ Ref: "AWS::Region" }, ":s3:path/bucket/key"
]
]
}
}
}));

test.done();
},

'use default integration from api'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit dc8a688

Please sign in to comment.