aws serverless.yml文件“找不到满足声明'opt:stage'的有效选项”错误

时间:2019-11-08 06:37:00

标签: jenkins aws-lambda serverless

在尝试运行无服务器时遇到警告。

无服务器警告-------------------------------------------- < / p>

找不到满足声明“ opt:stage”的有效选项。  下面是我的serverless.yml文件

# Serverless Config
service: api-service

# Provider
    provider:
      name: aws
      runtime: nodejs8.10
      region: ${opt:region, 'ap-east-1'}
      stage: ${opt:stage, 'dev'}
      # Enviroment Varibles
      environment:
        STAGE: ${self:custom.myStage}
        MONGO_DB_URI: ${file(./serverless.env.yml):${opt:stage}.MONGO_DB_URI}
        LAMBDA_ONLINE: ${file(./serverless.env.yml):${opt:stage}.LAMBDA_ONLINE}


    # Constants Varibles
    custom:
        # environments Variables used for convert string in upper case format
        environments:
        myStage: ${opt:stage, self:provider.stage}
        stages:
          - dev
          - qa
          - staging
          - production
        region:
          dev: 'ap-east-1'
          stage: 'ap-east-1'
          production: 'ap-east-1'

    # Function
    functions:
      testFunc:
        handler: index.handler
        description: ${opt:stage} API's
        events:
          - http:
              method: any
              path: /{proxy+}
              cors:
                origin: '*'

    #package
    package:
      exclude:
        - .env
        - node_modules/aws-sdk/**
        - node_modules/**

2 个答案:

答案 0 :(得分:1)

在testFunc的描述中,您正在使用org.springframework.batch.core。如果直接使用它,则在运行deploy命令时需要传递--stage标志。

您应该在那里使用- changeSet: id: 1234 author: adam.sandler changes: - sqlFile: encoding: utf8 path: classpath:/org/springframework/batch/core/schema-mysql.sql relativeToChangelogFile: false splitStatements: true stripComments: true ,因为在那里您将计算出阶段。

答案 1 :(得分:0)

我建议您在实现下方进行

provider:
  name: aws
  runtime: nodejs8.10
  region: ${opt:region, self:custom.environments.region.${self:custom.environments.myStage}}
  stage: ${opt:stage, self:custom.environments.myStage}
  # Enviroment Varibles
  environment:
    STAGE: ${self:custom.myStage}
    MONGO_DB_URI: ${file(./serverless.env.yml):${self:provider.stage}.MONGO_DB_URI}
    LAMBDA_ONLINE: ${file(./serverless.env.yml):${self:provider.stage}.LAMBDA_ONLINE}


# Constants Varibles
custom:
  # environments Variables used for convert string in upper case format
  environments:
    # set the default stage if not specified
    myStage: dev
    stages:
      - dev
      - qa
      - staging
      - production
    region:
      dev: 'ap-east-1'
      stage: 'ap-east-1'
      production: 'ap-east-1'

基本上,如果未使用命令行指定stageregion,则使用默认值。否则,将使用命令行一。