Skip to content

Commit

Permalink
fix(AWS API Gateway): Ensure that method depends on permission
Browse files Browse the repository at this point in the history
  • Loading branch information
nyamba committed Jun 25, 2021
1 parent a36247b commit 93b9027
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Expand Up @@ -20,6 +20,9 @@ module.exports = {
});
}

const apiGatewayPermission = this.provider.naming.getLambdaApiGatewayPermissionLogicalId(
event.functionName
);
const template = {
Type: 'AWS::ApiGateway::Method',
Properties: {
Expand All @@ -29,6 +32,7 @@ module.exports = {
RestApiId: this.provider.getApiGatewayRestApiId(),
OperationName: event.http.operationId,
},
DependsOn: [apiGatewayPermission],
};

if (event.http.private) {
Expand Down
Expand Up @@ -1816,4 +1816,23 @@ describe('#compileMethods v2()', () => {
expect(apiGatewayTokenMethodConfig.Properties.AuthorizerId).to.deep.equal('another-id');
});
});

it('should depends on permission resource', async () => {
const {
awsNaming,
cfTemplate: { Resources: cfResources },
} = await runServerless({
command: 'package',
fixture: 'apiGateway',
});
const FooApiGatewayMethodConfig = cfResources[awsNaming.getMethodLogicalId('Foo', 'GET')];
const OtherApiGatewayMethodConfig =
cfResources[awsNaming.getMethodLogicalId('BarMarkoVar', 'GET')];

const permNameFoo = awsNaming.getLambdaApiGatewayPermissionLogicalId('Foo');
const permNameOther = awsNaming.getLambdaApiGatewayPermissionLogicalId('Other');

expect(FooApiGatewayMethodConfig.DependsOn).to.include(permNameFoo);
expect(OtherApiGatewayMethodConfig.DependsOn).to.include(permNameOther);
});
});

0 comments on commit 93b9027

Please sign in to comment.