Serverless: تم عرض المتغيرات المشار إليها في Serverless.yml بشكل غير صحيح على أنها `[كائن كائن]`

تم إنشاؤها على ٢١ ديسمبر ٢٠١٦  ·  3تعليقات  ·  مصدر: serverless/serverless

هذا (تقرير خطأ / اقتراح ميزة)

وصف

عند استخدام site_config: ${file(./config/${opt:stage}/site.yml)} بناء الجملة في serverless.yml ملف المتغيرات المشار إليها في وقت لاحق في ملف serverless (مثلا: site_secret_key: ${self:site_config.site_secret_key} ) هي الانتاج في process.env.site_secret_key كما [Object object] حيث يجب أن تكون قيمة السلسلة المرتبطة بقيمة site_secret_key في الملف ./config/${opt:stage}/site.yml .

لاحظ أن استخدام بناء الجملة التالي يعمل بشكل صحيح:
${file(./config/${opt:stage}/site.yml):site_secret_key}

بيانات إضافية

  • إصدار Serverless Framework الذي تستخدمه : 1.3.0
  • نظام التشغيل : OSX 10.12.1
  • تتبع المكدس :
  • رسائل خطأ الموفر :
bug

التعليق الأكثر فائدة

إليك التهيئة التي توضح المشكلة:

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

لقد كتبت مكونًا إضافيًا لتفريغ serverless.service بدون الخاصية الرئيسية serverless :

% 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: {} }

لست متأكدًا تمامًا مما قد يتسبب في هذا الإخراج!

مصدر البرنامج المساعد كمرجع:

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;

ال 3 كومينتر

إليك التهيئة التي توضح المشكلة:

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

لقد كتبت مكونًا إضافيًا لتفريغ serverless.service بدون الخاصية الرئيسية serverless :

% 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: {} }

لست متأكدًا تمامًا مما قد يتسبب في هذا الإخراج!

مصدر البرنامج المساعد كمرجع:

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;

simonbuchan أظن أن المشكلة هي أنك أصبحت غير محدد config ، configEnv & configEnvProb تعريفها كأولاء serverless.yml بجوار الوظائف والموارد ... . إذا كنت أتذكر بشكل صحيح ، فقد وضعنا قيودًا على الخصائص المخصصة في serverless.yml ليتم تحميلها فقط داخل خاصية custom . لذا ، هل يمكنك محاولة نقل خصائصك المخصصة إلى كائن custom كما يلي:

custom:
  config:
  configEnv:
  ...

ولا تنس تحديث مراجعك

إغلاق منذ تحتاج إلى أن تتداخل في المتغيرات custom كماeahefnawy المقترحة أعلاه 🔝

هل كانت هذه الصفحة مفيدة؟
0 / 5 - 0 التقييمات