Can't return integer from Conditional function in cloud formation yaml

Viewed 318

I am writing a cloudformation serverless yaml for a lambda function. I need a conditional parameter reservedConcurrency to be 100 if IsProduction is true, 20 if false. But error happens when I deploy the yaml file: You should use integer as reservedConcurrency value on function

resources:
  Conditions:
    IsProduction:
      Fn::Equals:
        - ${self:provider.stage}
        - production

functions:  
  somefunction:
    handler: functions/somefunction
    timeout: 300
    events:
      - sqs:
          arn:
            Fn::GetAtt: [ somequeue, Arn ]
          batchSize: 10
    reservedConcurrency:
      Fn::If:
        - IsProduction
        - 100
        - 20
1 Answers

You can't use Cloudformation intrinsic functions within the functions block inside the serverless.yml file.

Instead try using nested variables

custom:
  concurrency:
    prod: 100

functions:  
  somefunction:
    handler: functions/somefunction
    timeout: 300
    events:
      - sqs:
          arn:
            Fn::GetAtt: [ somequeue, Arn ]
          batchSize: 10
    reservedConcurrency: ${self:custom.concurrency.${self:provider.stage}, 20}
Related