【问题标题】:Serverless cannot read the default value for stage even though I specified one即使我指定了一个,无服务器也无法读取阶段的默认值
【发布时间】:2018-12-12 10:59:00
【问题描述】:

嗨,当我尝试 serverless config 时,它返回了一个错误 Trying to populate non string value into a string for variable ${opt:stage}. Please make sure the value of the property is a string. 但是在我的 yml 文件中,我为 stage 指定了一个默认值:

 service: ''
    custom:
      prefixName: ''
      basePath: ''
      stagesPath: '${self:custom.basePath}config/stages'
      env: ${file(${self:custom.stagesPath}/${self:provider.stage}/env.yml)}
      baseUrl: ''
      warmup:
        schedule: 'cron(0/5 * ? * MON-FRI *)' # Run WarmUP every 5 minutes Mon-Fri
        prewarm: true # Run WarmUp immediately after a deployment
      prune:
        automatic: true
        number: 10
      appSync:
        - ${file(${self:custom.stagesPath}/${self:provider.stage}/appsyncUnaMe.yml)}
        # - ${file(${self:custom.stagesPath}/${self:provider.stage}/appsyncUnaCloudFeeds.yml)}
    provider:
      name: aws
      runtime: nodejs8.10
      role:  ${self:custom.env.role}
      stage: ${opt:stage, 'dev'}
      region: ${self:custom.env.region}
      vpc: ${self:custom.env.vpc}
      profile: ${self:custom.env.profile}
      environment: 
        APPSYNC_UNAME_API_X_API_KEY: ${opt:appsyncKey}
        APPSYNC_UNAME_API_X_URI: ${opt:appsyncUri}
        STAGE_NAME: ${opt:stage, 'dev'}
        SERVICE_NAME: ${self:custom.prefixName}
      timeout: 10
      deploymentBucket: ${self:custom.env.deploymentBucket}
      versionFunctions: false
    package:
      individually: true
      exclude:
        - ".*/**"
    plugins:
      # - serverless-webpack
      - serverless-plugin-warmup
      - serverless-prune-plugin
      - serverless-appsync-plugin
      - serverless-offline

    functions:
      ${file(${self:custom.stagesPath}/${self:provider.stage}/resolvers1.yml)}

操作系统:达尔文 节点版本:8.11.1 无服务器版本:1.27.3

为什么会出现这个错误?

【问题讨论】:

    标签: serverless-framework


    【解决方案1】:

    你错过了另一个。

    environment:
      STAGE_NAME: ${opt:stage}
    

    【讨论】:

    • 仍然有同样的错误。跟踪 yml 真的很头疼。
    猜你喜欢
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 2011-03-24
    • 2014-04-19
    • 2014-12-06
    • 2021-12-18
    • 2017-03-24
    相关资源
    最近更新 更多