fix(AWS Lambda): Ensure proper DependsOn settings when url: true

This commit is contained in:
Piotr Grzesik 2022-05-12 18:25:03 +02:00
parent 5af44a478e
commit 2107aec965
2 changed files with 43 additions and 0 deletions

View File

@ -659,6 +659,7 @@ class AwsCompileFunctions {
AuthType: auth,
TargetFunctionArn: resolveLambdaTarget(functionName, functionObject),
},
DependsOn: _.get(functionObject.targetAlias, 'logicalId'),
};
if (cors) {
@ -690,6 +691,7 @@ class AwsCompileFunctions {
Principal: '*',
FunctionUrlAuthType: auth,
},
DependsOn: _.get(functionObject.targetAlias, 'logicalId'),
};
}
}

View File

@ -1677,6 +1677,11 @@ describe('lib/plugins/aws/package/compile/functions/index.test.js', () => {
},
},
},
fnUrlWithProvisioned: {
handler: 'target.handler',
url: true,
provisionedConcurrency: 1,
},
},
resources: {
Resources: {
@ -1900,6 +1905,42 @@ describe('lib/plugins/aws/package/compile/functions/index.test.js', () => {
});
});
it('should support `functions[].url` set to `true` with provisionedConcurrency set', () => {
expect(
cfResources[naming.getLambdaFunctionUrlLogicalId('fnUrlWithProvisioned')].Properties
).to.deep.equal({
AuthType: 'NONE',
TargetFunctionArn: {
'Fn::Join': [
':',
[
{
'Fn::GetAtt': ['FnUrlWithProvisionedLambdaFunction', 'Arn'],
},
'provisioned',
],
],
},
});
expect(
cfResources[naming.getLambdaFunctionUrlLogicalId('fnUrlWithProvisioned')].DependsOn
).to.equal('FnUrlWithProvisionedProvConcLambdaAlias');
expect(
cfResources[naming.getLambdaFnUrlPermissionLogicalId('fnUrl')].Properties
).to.deep.equal({
Action: 'lambda:InvokeFunctionUrl',
FunctionName: {
'Fn::GetAtt': ['FnUrlLambdaFunction', 'Arn'],
},
FunctionUrlAuthType: 'NONE',
Principal: '*',
});
expect(
cfResources[naming.getLambdaFnUrlPermissionLogicalId('fnUrlWithProvisioned')].DependsOn
).to.equal('FnUrlWithProvisionedProvConcLambdaAlias');
});
it('should support `functions[].url` set to an object with authorizer and cors', () => {
expect(
cfResources[naming.getLambdaFunctionUrlLogicalId('fnUrlWithAuthAndCors')].Properties