Skip to content

Trying to populate non string value into a string for variable #3714

Closed

Description

@elioncho

This is a (Bug Report)

Description

  • What went wrong?
    I updated to the latest version of Serverless and I'm now getting an error when I invoke functions locally without adding the stage option in the command line.
  • What did you expect should have happened?
    The function should have been executed without an issue using the default stage as it was set up in the serverless.yml
provider:
  name: aws
  stage: dev
  custom:
    stage: ${opt:stage, self:provider.stage}
  • What was the config you used?
     OS:                 darwin
     Node Version:       6.10.3
     Serverless Version: 1.14.0
  • What stacktrace or error message from your provider did you see?
 Serverless Warning --------------------------------------
 
     A valid option to satisfy the declaration 'opt:stage'
     could not be found.
 
 
  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.
 
  Stack Trace --------------------------------------------
 
ServerlessError: Trying to populate non string value into a string for variable ${opt:stage}. Please make sure the value of the property is a string.
    at Variables.populateVariable (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:143:17)
    at singleValueToPopulate.then.valueToPopulate (/usr/local/lib/node_modules/serverless/lib/classes/Variables.js:109:23)
    at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Activity

  1. HyperBrain commented on May 31, 2017

    @HyperBrain
    Contributor

    @pmuens @eahefnawy This could be an additional issue with the new variable system. This example uses the defaults notation (${..., ...}). Nevertheless the issue should be verified independently first.

  2. pmuens commented on Jun 1, 2017

    @pmuens
    Contributor

    @elioncho @HyperBrain thanks for reporting and investigating.

    Yes, it looks like smth. is broken there 🤔 Should be easy to reproduce...

  3. jliebrand commented on Jun 8, 2017

    @jliebrand

    Just run in to the same issue. Trying to work around the fact you can't specify Fn::GetAtt as an arn for the authorizer. So instead, I created three different ARNs in my custom section, and then used this:

              authorizer:
                arn: ${self:custom.${opt:stage}UserPool}
    

    This seems to work ok on my mac, but when I run it on CI/CD (linux) it fails with the same error:
    A valid option to satisfy the declaration 'opt:stage' could not be found.

  4. jliebrand commented on Jun 8, 2017

    @jliebrand

    Ah.. i'm using 1.13.2 on my mac, whereas the CI/CD server is running 1.14.0... that might explain it, especially if @HyperBrain mentioned the "new variable system"?

  5. jliebrand commented on Jun 8, 2017

    @jliebrand

    Just upgraded both to 1.15.1 and still the same: this works on my mac, but not on linux

  6. jliebrand commented on Jun 8, 2017

    @jliebrand

    Tried all of these invocations, none work:
    --stage production
    --stage=production
    --stage="production"

    Without the ${opt:stage} things do work (in that it deploys to app-[stage]). So I'm guessing on linux it just doesn't populate the "opt" struct?

  7. jliebrand commented on Jun 8, 2017

    @jliebrand

    Aahhh.. this seems to be a problem with how i'm invoking serverless on CI/CD... I'm doing this:

    serverless config credentials --provider aws --key KEYXXX --secret SECRETXXX && serverless deploy --stage dev

    This breaks assumptions made in CLI.js I think...

  8. jliebrand commented on Jun 8, 2017

    @jliebrand

    Ok "fixed" this... the config command I was running doesn't need a --stage but the way I had set up my yml meant it would complain if it's not there...

    So I added --stage to the config command which fixed things..

  9. pmuens commented on Jun 13, 2017

    @pmuens
    Contributor

    Thanks for sharing the steps to reproduce @jliebrand 👍

    /cc @eahefnawy @brianneisler 🔝

  10. pmuens commented on Feb 7, 2019

    @pmuens
    Contributor

    Closing since this is quite a stale issue and we've published newer versions with lots of fixes for this in the past.

    Feel free to re-open if this is still an issue.

  11. dmitry-grinko commented on Jul 20, 2019

    @dmitry-grinko

    if you are using ${opt:stage} you should run sls deploy --stage dev

  12. connor11528 commented on Apr 3, 2020

    @connor11528

    I'm new to serverless and just got this same error when trying to login. Is there a fix here or something I need to configure to login and run deployments?

    $ serverless login
    
     Serverless Warning --------------------------------------
    
      A valid option to satisfy the declaration 'opt:stage' could not be found.
    
    
      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.
    
      Get Support --------------------------------------------
         Docs:          docs.serverless.com
         Bugs:          github.com/serverless/serverless/issues
         Issues:        forum.serverless.com
    
      Your Environment Information ---------------------------
         Operating System:          darwin
         Node Version:              8.9.1
         Framework Version:         1.67.0
         Plugin Version:            3.6.3
         SDK Version:               2.3.0
         Components Version:        2.28.0
    
  13. Neeraj-Almabetter commented on Aug 27, 2024

    @Neeraj-Almabetter

    anyone got any solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions