Skip to content

Commit

Permalink
fix(apigateway): lambda integration does not recognize allowTestInvoke (
Browse files Browse the repository at this point in the history
#10828)

Fixes the issue of handling `allowTestInvoke: true` like `allowTestInovke: false` in `LambdaIntegration`.

fixes #7605
related: #7604


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
  • Loading branch information
wtho committed Oct 16, 2020
1 parent 9b2438a commit 650c23f
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export class LambdaIntegration extends AwsIntegration {
});

this.handler = handler;
this.enableTest = options.allowTestInvoke === undefined ? true : false;
this.enableTest = options.allowTestInvoke === undefined ? true : options.allowTestInvoke;
}

public bind(method: Method): IntegrationConfig {
Expand Down
38 changes: 38 additions & 0 deletions packages/@aws-cdk/aws-apigateway/test/test.lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,44 @@ export = {
test.done();
},

'"allowTestInvoke" set to true allows calling the API from the test UI'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
const fn = new lambda.Function(stack, 'Handler', {
runtime: lambda.Runtime.NODEJS_10_X,
code: lambda.Code.fromInline('foo'),
handler: 'index.handler',
});

const api = new apigateway.RestApi(stack, 'api');

// WHEN
const integ = new apigateway.LambdaIntegration(fn, { allowTestInvoke: true });
api.root.addMethod('GET', integ);

// THEN
expect(stack).to(haveResource('AWS::Lambda::Permission', {
SourceArn: {
'Fn::Join': [
'',
[
'arn:',
{ Ref: 'AWS::Partition' },
':execute-api:',
{ Ref: 'AWS::Region' },
':',
{ Ref: 'AWS::AccountId' },
':',
{ Ref: 'apiC8550315' },
'/test-invoke-stage/GET/',
],
],
},
}));

test.done();
},

'"proxy" can be used to disable proxy mode'(test: Test) {
// GIVEN
const stack = new cdk.Stack();
Expand Down

0 comments on commit 650c23f

Please sign in to comment.