Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
feat(AWS Lambda): Support Fn::If for Principal.AWS
  • Loading branch information
pgrzesik committed Jun 30, 2021
1 parent ae5be0f commit 894ac5b
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/plugins/aws/provider.js
Expand Up @@ -357,6 +357,19 @@ class AwsProvider {
additionalProperties: false,
required: ['Fn::ImportValue'],
},
awsCfIf: {
type: 'object',
properties: {
'Fn::If': {
type: 'array',
minItems: 3,
maxItems: 3,
items: { type: 'string', minLength: 1 },
},
},
required: ['Fn::If'],
additionalProperties: false,
},
awsCfImportLocallyResolvable: {
type: 'object',
properties: {
Expand Down Expand Up @@ -438,6 +451,7 @@ class AwsProvider {
AWS: {
anyOf: [
{ const: '*' },
{ $ref: '#/definitions/awsCfIf' },
{
type: 'array',
items: {
Expand Down
Expand Up @@ -191,4 +191,34 @@ describe('lib/plugins/aws/package/compile/events/apiGateway/lib/restApi.test.js'

expect(resource.Properties.DisableExecuteApiEndpoint).to.equal(true);
});

it('should support `provider.apiGateway.resourcePolicy[].Principal.AWS with Fn::If`', async () => {
const { cfTemplate } = await runServerless({
fixture: 'apiGateway',
command: 'package',
configExt: {
provider: {
apiGateway: {
resourcePolicy: [
{
Effect: 'Allow',
Principal: {
AWS: {
'Fn::If': ['Condition', 'FirstVal', 'SecondVal'],
},
},
Action: 'execute-api:Invoke',
Resource: ['execute-api:/*/*/*'],
},
],
},
},
},
});
const resource = cfTemplate.Resources.ApiGatewayRestApi;

expect(resource.Properties.Policy.Statement[0].Principal.AWS).to.deep.equal({
'Fn::If': ['Condition', 'FirstVal', 'SecondVal'],
});
});
});

0 comments on commit 894ac5b

Please sign in to comment.