mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
fix(AWS HTTP API): Properly handle authorizer function with alias
This commit is contained in:
parent
bb0484e6b5
commit
0ca6aaae52
@ -294,8 +294,7 @@ class HttpApiEvents {
|
||||
};
|
||||
|
||||
if (functionObject && functionObject.targetAlias) {
|
||||
permissionResource.Properties.DependsOn =
|
||||
this.provider.naming.getLambdaLogicalId(functionName);
|
||||
permissionResource.DependsOn = functionObject.targetAlias.logicalId;
|
||||
}
|
||||
this.cfTemplate.Resources[authorizerPermissionLogicalId] = permissionResource;
|
||||
}
|
||||
|
||||
@ -550,6 +550,82 @@ describe('lib/plugins/aws/package/compile/events/httpApi.test.js', () => {
|
||||
expect(cfResources[authorizerPermissionLogicalId]).to.be.undefined;
|
||||
});
|
||||
|
||||
it('should correctly set `DependsOn` property on permission resource for functions with provisioned concurrency', async () => {
|
||||
const { awsNaming, cfTemplate } = await runServerless({
|
||||
fixture: 'httpApi',
|
||||
configExt: {
|
||||
provider: {
|
||||
httpApi: {
|
||||
authorizers: {
|
||||
someAuthorizer: {
|
||||
type: 'request',
|
||||
identitySource: '$request.header.Authorization',
|
||||
functionName: 'other',
|
||||
resultTtlInSeconds: 300,
|
||||
enableSimpleResponses: true,
|
||||
payloadVersion: '2.0',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
functions: {
|
||||
other: {
|
||||
provisionedConcurrency: 1,
|
||||
},
|
||||
foo: {
|
||||
events: [
|
||||
{
|
||||
httpApi: {
|
||||
authorizer: {
|
||||
name: 'someAuthorizer',
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
command: 'package',
|
||||
});
|
||||
const authorizerPermissionLogicalId =
|
||||
awsNaming.getLambdaAuthorizerHttpApiPermissionLogicalId('someAuthorizer');
|
||||
expect(cfTemplate.Resources[authorizerPermissionLogicalId]).to.deep.equal({
|
||||
Type: 'AWS::Lambda::Permission',
|
||||
Properties: {
|
||||
FunctionName: {
|
||||
'Fn::Join': [
|
||||
':',
|
||||
[
|
||||
{
|
||||
'Fn::GetAtt': ['OtherLambdaFunction', 'Arn'],
|
||||
},
|
||||
'provisioned',
|
||||
],
|
||||
],
|
||||
},
|
||||
Action: 'lambda:InvokeFunction',
|
||||
Principal: 'apigateway.amazonaws.com',
|
||||
SourceArn: {
|
||||
'Fn::Join': [
|
||||
'',
|
||||
[
|
||||
'arn:',
|
||||
{ Ref: 'AWS::Partition' },
|
||||
':execute-api:',
|
||||
{ Ref: 'AWS::Region' },
|
||||
':',
|
||||
{ Ref: 'AWS::AccountId' },
|
||||
':',
|
||||
{ Ref: naming.getHttpApiLogicalId() },
|
||||
'/*',
|
||||
],
|
||||
],
|
||||
},
|
||||
},
|
||||
DependsOn: 'OtherProvConcLambdaAlias',
|
||||
});
|
||||
});
|
||||
|
||||
it('should throw when request authorizer does not have "functionName" and "functionArn" defined', async () => {
|
||||
await expect(
|
||||
runServerless({
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user