Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

aws serverless.yml file "A valid option to satisfy the declaration 'opt:stage' could not be found" error

Getting below warning when trying to run serverless.

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

A valid option to satisfy the declaration 'opt:stage' could not be found. Below is my serverless.yml file

# 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/**
like image 518
vimmi Avatar asked Nov 08 '19 06:11

vimmi


People also ask

What is unresolvedvariablesnotificationmode in yml?

Variables allow users to dynamically replace config values in serverless.yml config. They are especially useful when providing secrets for your service to use and when you are working with multiple stages. If unresolvedVariablesNotificationMode is set to error, references to variables that cannot be resolved will result in an error being thrown.

How do I reference environment variables in a yml file?

Referencing Environment Variables To reference environment variables, use the $ {env:SOME_VAR} syntax in your serverless.yml configuration file. It is valid to use the empty string in place of SOME_VAR.

How do I use self reference in yml serverless?

Reference Properties In serverless.yml To self-reference properties in serverless.yml, use the $ {self:someProperty} syntax in your serverless.yml. someProperty can contain the empty string for a top-level self-reference or a dotted attribute reference to any depth of attribute, so you can go as shallow or deep in the object tree as you want.

What properties are available when the provider is set to AWS?

Here is a list of all available properties in serverless.yml when the provider is set to aws. 1 # serverless.yml 2 3 service: myService 4 5 projectDir: ./ # Boundary of a project in which service is configured.


1 Answers

In the description of the testFunc you're using ${opt:stage}. If you use that directly you need to pass the --stage flag when you run the deploy command.

What you should do there is to use the ${self:provider.stage}, because there you will have the stage calculated.

like image 138
vgaltes Avatar answered Sep 28 '22 01:09

vgaltes