1

I have a CommaDelimitedList and need to put it into a policy JSON property as JSONArray:

  Parameters:
    ApiAllowedIps:
      Type: CommaDelimitedList

  RestApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
      ...
      Policy: !Sub | 
        {
           ...
              "Condition": {
                  "NotIpAddress": {
                       "aws:SourceIp": [${ApiAllowedIps}]
                   }
              }
        }

I tried many combinations but without success.

Marcin
  • 215,873
  • 14
  • 235
  • 294
Radagast
  • 509
  • 10
  • 23

1 Answers1

1

Normally you would use YAML for that, not JSON. For example:

  Parameters:
    ApiAllowedIps:
      Type: CommaDelimitedList

  RestApi:
    Type: AWS::ApiGateway::RestApi
    Properties:
      ...
      Policy: 
        Version: "2012-10-17"
        Statement:
          - Effect: Allow
            Action: '*'
            Principal: '*'
            Resource: '*'
            Condition:
              NotIpAddress:
                aws:SourceIp: !Ref ApiAllowedIps      
Marcin
  • 215,873
  • 14
  • 235
  • 294
  • Yes, but AWS::ApiGateway::RestApi only takes JSON as 'Policy' value, which is weird. See https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-apigateway-restapi.html#cfn-apigateway-restapi-policy – Radagast Dec 30 '21 at 02:03
  • See also the comments 'FYI': https://stackoverflow.com/a/55614656/5336824 – Radagast Dec 30 '21 at 02:11
  • @Radagast YAML policy works perfectly fine. I use it in my templates. YAML is the only way to do what you want. – Marcin Dec 30 '21 at 03:43
  • 1
    I tested here and it worked, thanks. So, do you have clues on why in these other questions there are people saying to use only JSON? – Radagast Dec 30 '21 at 04:21