无法从云形成yaml中的条件函数返回整数

时间:2018-12-28 17:53:07

标签: aws-lambda yaml amazon-cloudformation serverless-framework

我正在为lambda函数编写无cloudformation无服务器yaml。如果IsProduction为true,则我需要一个条件参数reservedConcurrency为100,如果为false,则为20。但是,当我部署yaml文件时会发生错误: 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 个答案:

答案 0 :(得分:1)

您不能在functions文件内的serverless.yml块中使用Cloudformation内部函数。

请尝试使用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}