在无服务器框架中找不到满足声明的有效选项

时间:2019-09-13 09:29:13

标签: serverless-framework bitbucket-pipelines

我正在使用无服务器框架,并使用 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}

我希望能够传递CLIenvironment variables中的变量。

我已经在位桶管道变量中为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.

1 个答案:

答案 0 :(得分:0)

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

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'}

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