Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Referenced variables in the Serverless.yml incorrectly rendered as [Object object] #3003

Closed
TimothyDalbey opened this issue Dec 21, 2016 · 3 comments
Labels

Comments

@TimothyDalbey
Copy link

This is a (Bug Report / Feature Proposal)

Description

When using site_config: ${file(./config/${opt:stage}/site.yml)} syntax in the serverless.yml file the variables referenced later in the serverless file (ex: site_secret_key: ${self:site_config.site_secret_key}) are output in process.env.site_secret_key as [Object object] where it should have been the string value associated with the site_secret_key value in the ./config/${opt:stage}/site.yml file.

Note that using the following syntax works correctly:
${file(./config/${opt:stage}/site.yml):site_secret_key}

Additional Data

  • Serverless Framework Version you're using:1.3.0
  • Operating System:OSX 10.12.1
  • Stack Trace:
  • Provider Error messages:
@pmuens pmuens added the bug label Dec 22, 2016
@simonbuchan
Copy link
Contributor

simonbuchan commented Jan 19, 2017

Here's my config demonstrating the problem:

service: test-service

plugins:
  - debug-plugin

config: ${file(config.json)}
configEnv: ${file(config.json):env}
configEnvProp: ${file(config.json):env.development}

provider:
  name: aws
  stage: development
  runtime: nodejs4.3
  environment:
    NODE_ENV: ${self:provider.stage}
    fileConfig: ${file(config.json)}
    fileConfigEnv: ${file(config.json):env}
    fileConfigEnvProp: ${file(config.json):env.development}
    selfConfig: ${self:config}
    selfConfigEnv: ${self:configEnv}
    selfConfigEnvProp: ${self:configEnvProp}
    selfConfigDotEnv: ${self:config.env}
    selfConfigDotEnvDotProp: ${self:config.env.development}

functions:
  hello:
    handler: handler.hello

I wrote a plugin to dump serverless.service without the serverless parent prop:

% sls debug config
{ service: 'test-service',
  provider:
   { name: 'aws',
     stage: 'development',
     runtime: 'nodejs4.3',
     environment:
      { NODE_ENV: 'development',
        fileConfig:
         { env:
            { development: { region: 'ap-northeast-2' },
              production: { region: 'us-west-1' } },
           assets: { bucket: 'some-bucket' } },
        fileConfigEnv:
         { development: { region: 'ap-northeast-2' },
           production: { region: 'us-west-1' } },
        fileConfigEnvProp: { region: 'ap-northeast-2' },
        selfConfig: undefined,
        selfConfigEnv: undefined,
        selfConfigEnvProp: undefined,
        selfConfigDotEnv: {},
        selfConfigDotEnvDotProp: undefined },
     region: 'us-east-1',
     variableSyntax: '\\${([ :a-zA-Z0-9._,\\-\\/\\(\\)]+?)}' },
  defaults:
   { stage: 'development',
     region: 'us-east-1',
     variableSyntax: '\\${([ :a-zA-Z0-9._,\\-\\/\\(\\)]+?)}' },
  custom: undefined,
  plugins: [ 'debug-plugin' ],
  functions:
   { hello:
      { handler: 'handler.hello',
        events: [],
        name: 'test-service-development-hello' } },
  resources: undefined,
  package: {} }

Not quite sure what could cause that output!

Plugin source for reference:

class Debug {
  constructor(serverless, options) {
    this.serverless = serverless;
    this.options = options;

    this.commands = {
      debug: {
        usage: 'Debugging',
        commands: {
          config: {
            usage: 'Show configuration value',
            lifecycleEvents: [
              'print'
            ]
          }
        }
      }
    };

    this.hooks = {
      'debug:config:print': () => this.printConfig(),
    };
  }

  printConfig() {
    const config = Object.assign({}, this.serverless.service);
    delete config.serverless;
    const output = require('util').inspect(config, { colors: true, depth: null });
    console.log(output.substring(0, 100000)); // Paranoia: can't kill node sync output on Ubuntu on Windows?
  }
}

module.exports = Debug;

@eahefnawy
Copy link
Member

@simonbuchan I'm guessing the issue is that you're getting undefined for your variable references? I think the reason is that you have config, configEnv & configEnvProb properties defined as first parents of serverless.yml right next to functions and resources...etc. If I remember correctly, we put a restriction on custom properties in serverless.yml to only be loaded inside a custom property. So could you try moving your custom properties into custom object like so:

custom:
  config:
  configEnv:
  ...

And dont forget to update your references

@pmuens
Copy link
Contributor

pmuens commented May 19, 2017

Closing since the variables need to be nested in custom as @eahefnawy suggested above 🔝

@pmuens pmuens closed this as completed May 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants