Skip to content

Can not use Fn::if within CustomStatements: #1218

@eerb-kyruus

Description

@eerb-kyruus

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

  1. Create a serverless API template with this in the conditional section:
    Conditions:
    IsProd:
  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions