【问题标题】:A valid option to satisfy the declaration could not be found in serverless framework在无服务器框架中找不到满足声明的有效选项
【发布时间】:2020-01-15 04:03:38
【问题描述】:

我正在使用 serverless 框架并使用 bitbucket-pipeline 来配置 CI/CD。

我在serverless.yml文件中有如下配置

provider:
  name: aws
  runtime: nodejs10.x
  region: ${opt:region, ${env:AWS_REGION, 'ap-south-1'}}
  memorySize: ${opt:memory, ${env:MEMORY_SIZE, 512}}tracing:
  apiGateway: ${env:TRACING_API_GATEWAY, true}

我希望能够从CLI 和environment variables 传递变量。

我在 bitbucket 管道变量中为AWS_REGION 设置了环境变量,但没有为MEMORY_SIZE 设置环境变量,因为我想使用默认值。

但这会在运行管道时出错。

Serverless Warning --------------------------------------

  A valid option to satisfy the declaration 'opt:region,ap-south-1' could not be found.

Serverless Warning --------------------------------------

  A valid environment variable to satisfy the declaration 'env:MEMORY_SIZE,512' could not be found.


Serverless Warning --------------------------------------

  A valid environment variable to satisfy the declaration 'env:TRACING_API_GATEWAY,true' could not be found.

【问题讨论】:

    标签: serverless-framework bitbucket-pipelines


    【解决方案1】:

    首先,这些是警告而不是错误。无服务器错误类似于:

    Serverless Error ---------------------------------------
    
    Trying to populate non string value into a string for variable ${opt:stage}. Please make sure the value of the property is a string.
    

    发生此特定错误是因为在我声明的custom 标记中:var: ${opt:stage}-something 应更改为:

    provider:
      stage: ${opt:stage, 'local'}
    
    custom:
      var: ${self:provider.stage}-something
    

    我认为在您的情况下,您需要像这样更新区域:

    region: ${opt:region, env:AWS_REGION, 'ap-south-1'}
    

    虽然我无法重现最后一个警告,但我认为 ENV 变量应该在 args 或 variables 下的 bitbucket-pipelines.yml(或类似的 CI 管道 YAML)中定义,然后可以使用 ${env:VAR} 访问它们。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-29
      • 2020-10-22
      • 1970-01-01
      • 1970-01-01
      • 2021-04-18
      • 2012-01-17
      相关资源
      最近更新 更多