question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

A valid service attribute to satisfy the declaration 'self:service.name' could not be found

See original GitHub issue

This is a (Bug Report)

Description

For bug reports:

  • What went wrong?

I’m trying to use dynamic variables in serverless.yml and it fails. Basically, I have the following in my provider:

  environment:
    SERVICE_NAME: ${self:service.name}
    DYNAMODB_TABLE: ${self:service.name}-test

The SERVICE_NAME is correctly resolved IF I comment the DYNAMODB_TABLE: "${self:service.name}-test", otherwise it fails with the following stack trace.

If I use ${self:service.name} alone it works, but if I add some string after, then it fails: ${self:service.name}-test

  • What did you expect should have happened?

Resolving variables correctly

  • What stacktrace or error message from your provider did you see?
➜  simulator-feedback git:(master) ✗ sls print
Serverless: Load command run
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command login
Serverless: Load command logout
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command emit
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command webpack
 
 Serverless Warning --------------------------------------
 
  A valid service attribute to satisfy the declaration 'self:service.name' could not be found.
 
 
 Serverless Warning --------------------------------------
 
  A valid service attribute to satisfy the declaration 'self:service.name' could not be found.
 
 
  Serverless Error ---------------------------------------
 
  Trying to populate non string value into a string for variable ${self:service.name}. 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 ${self:service.name}. Please make sure the value of the property is a string.
    at Variables.populateVariable (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:156:13)
    at pendingMatches.push.pendingMatch.then.matchedValue (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:124:21)
    at runCallback (timers.js:789:20)
    at tryOnImmediate (timers.js:751:5)
    at processImmediate [as _immediateCallback] (timers.js:722:5)
From previous event:
    at property.match.forEach (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:122:40)
    at Array.forEach (<anonymous>)
    at Variables.populateProperty (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:111:41)
    at forEachLeaf (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:85:14)
    at forEachLeaf (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:75:14)
    at addContext (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:62:42)
    at /Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:13392:38
    at /Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:4917:15
    at baseForOwn (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:3002:24)
    at Function.mapValues (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:13391:7)
    at forEachLeaf (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:73:37)
    at addContext (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:62:42)
    at /Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:13392:38
    at /Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:4917:15
    at baseForOwn (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:3002:24)
    at Function.mapValues (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:13391:7)
    at forEachLeaf (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:73:37)
    at addContext (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:62:42)
    at /Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:13392:38
    at /Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:4917:15
    at baseForOwn (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:3002:24)
    at Function.mapValues (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/node_modules/lodash/lodash.js:13391:7)
    at forEachLeaf (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:73:37)
    at Variables.populateObject (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:79:5)
    at Variables.populateService (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/classes/Variables.js:47:17)
    at Serverless.run (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/lib/Serverless.js:89:27)
    at serverless.init.then (/Users/vadorequest/.nvm/versions/node/v8.9.4/lib/node_modules/serverless/bin/serverless:42:50)
    at <anonymous>
 
  Get Support --------------------------------------------
     Docs:          docs.serverless.com
     Bugs:          github.com/serverless/serverless/issues
     Forums:        forum.serverless.com
     Chat:          gitter.im/serverless/serverless
 
  Your Environment Information -----------------------------
     OS:                     darwin
     Node Version:           8.9.4
     Serverless Version:     1.26.0

Similar or dependent issues:

Additional Data

  • Operating System: MacOS X

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:23 (23 by maintainers)

github_iconTop GitHub Comments

4reactions
dschepcommented, Feb 21, 2018

Here’s a trick I just figured out for using ${self:service.name} using YAML references:

service: &service
  name: hello                                                                      
custom:
  service: *service

Then use ${self:custom.service.name} instead.

2reactions
erikeriksoncommented, Feb 23, 2018

The following adds support for the expected-to-be valid references below:

 +    if (variable === 'self:service.name') {
 +      variable = 'self:service';
 +    }
 +    if (variable === 'self:provider') {
 +      variable = 'self:provider.name';
 +    }

This is available on #4754 if you would like to test it out. Others, feel free to object.

Read more comments on GitHub >

github_iconTop Results From Across the Web

aws serverless.yml file "A valid option to satisfy the declaration ...
Basically, if stage and region is not specified using command line, then use defaults. Otherwise the command line one will be used.
Read more >
serverless/serverless - Gitter
... to satisfy the declaration 'self:frameworkVersion' could not be found. ... does not work ? isn't it just like ${self:service} to get the...
Read more >
A valid environment variable to satisfy the declaration 'env:url ...
I am setting up a VAR named URL in my enviroment gitlab config: ... variable to satisfy the declaration 'env:url' could not be...
Read more >
Serving a Lambda function via a custom domain
The subdomain is defined in Route53, but I did not find a ... A valid service attribute to satisfy the declaration 'self:vars.
Read more >
Faculty Course Planning | Registrar
Please make sure to click “Submit” and NOT “Save” as this will not start the ... through the following pages: Self-Service > My...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found