Skip to content

Commit 7623756

Browse files
authored
Merge pull request #102 from tazorax/invoke-permission-none-auth
Adding `lambda:InvokeFunction` permission for function url with `NONE` auth type
2 parents 5c98cac + 847ccea commit 7623756

File tree

4 files changed

+29
-0
lines changed

4 files changed

+29
-0
lines changed

lib/plugins/aws/lib/naming.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,9 @@ module.exports = {
541541
getLambdaHttpApiPermissionLogicalId(functionName) {
542542
return `${this.getNormalizedFunctionName(functionName)}LambdaPermissionHttpApi`;
543543
},
544+
getLambdaFnPermissionLogicalId(functionName) {
545+
return `${this.getNormalizedFunctionName(functionName)}LambdaPermissionFn`;
546+
},
544547
getLambdaFnUrlPermissionLogicalId(functionName) {
545548
return `${this.getNormalizedFunctionName(functionName)}LambdaPermissionFnUrl`;
546549
},

lib/plugins/aws/package/compile/functions.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,16 @@ class AwsCompileFunctions {
723723
},
724724
DependsOn: _.get(functionObject.targetAlias, 'logicalId'),
725725
};
726+
cfTemplate.Resources[this.provider.naming.getLambdaFnPermissionLogicalId(functionName)] = {
727+
Type: 'AWS::Lambda::Permission',
728+
Properties: {
729+
FunctionName: resolveLambdaTarget(functionName, functionObject),
730+
Action: 'lambda:InvokeFunction',
731+
Principal: '*',
732+
InvokedViaFunctionUrl: true,
733+
},
734+
DependsOn: _.get(functionObject.targetAlias, 'logicalId'),
735+
};
726736
}
727737
}
728738

test/unit/lib/plugins/aws/lib/naming.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1064,6 +1064,14 @@ describe('#naming()', () => {
10641064
});
10651065
});
10661066

1067+
describe('#getLambdaFnPermissionLogicalId()', () => {
1068+
it('should normalize the name and append correct suffix', () => {
1069+
expect(sdk.naming.getLambdaFnPermissionLogicalId('fnName')).to.equal(
1070+
'FnNameLambdaPermissionFn'
1071+
);
1072+
});
1073+
});
1074+
10671075
describe('#getHttpApiName()', () => {
10681076
it('should return the composition of service & stage name if custom name not provided and shouldStartNameWithService is true', () => {
10691077
serverless.service.service = 'myService';

test/unit/lib/plugins/aws/package/compile/functions.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1958,6 +1958,14 @@ describe('lib/plugins/aws/package/compile/functions/index.test.js', () => {
19581958
FunctionUrlAuthType: 'NONE',
19591959
Principal: '*',
19601960
});
1961+
expect(cfResources[naming.getLambdaFnPermissionLogicalId('fnUrl')].Properties).to.deep.equal({
1962+
Action: 'lambda:InvokeFunction',
1963+
FunctionName: {
1964+
'Fn::GetAtt': ['FnUrlLambdaFunction', 'Arn'],
1965+
},
1966+
InvokedViaFunctionUrl: true,
1967+
Principal: '*',
1968+
});
19611969
});
19621970

19631971
it('should support `functions[].url` set to `true` with provisionedConcurrency set', () => {

0 commit comments

Comments
 (0)