-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Description
Description:
I am attempting to write a custom policy for my Serverless api that depends on deployment type. The serverless transform expects a list inside the CustomStatements: label, preventing use of fn:If to conditionally set policies. The obvious work-around is to specify the entire swagger document myself, but this creates lots of duplication and a huge template.
Steps to reproduce the issue:
NOTE: Confidential parts of the template have been redacted
- Create a serverless API template with this in the conditional section:
Conditions:
IsProd:
- Create a conditional resource policy like the following in the AWS:Serverless:Api Auth: section:
ResourcePolicy:
CustomStatements:
Fn::If:
- IsProd
- - Principal: '*'
Effect: Allow
Action: <redacted>
Resource: <redacted>
- - Principal: '*'
Effect: Allow
Action: <redacted>
Resource: <redacted>
Condition:
<redacted>Observed result:
The macro creates the following within the swagger doc, reformatted for readability. Note carefully the extra set of square brackets around the policy statement:
"x-amazon-apigateway-policy":
{
"Version":"2012-10-17","Statement":
[
[
{
Condition":
{
<redacted>
},
"Action": <redacted>
"Resource": <redacted>
"Effect":"Allow",
"Principal":"*"
}
]
]
},The deploy fails due to that extra set of square brackets in the policy statement
Expected result:
The swagger gateway policy is created with a single set of square brackets and the deploy succeeds.