无服务器:将文件导入自定义和其他变量

问题描述

我有一个serverless.common.yml,具有应由所有服务共享的属性

service: ixxxx
custom:
  stage: ${opt:stage,self:provider.stage}
  resourcesstages:
    prod: prod
    dev: dev
  resourcesstage: ${self:custom.resourcesstages.${self:custom.stage},self:custom.resourcesstages.dev}

lambdaPolicyXRay:
  Effect: Allow
  Action:
    - xray:PutTraceSegments
    - xray:PutTelemetryRecords
  Resource: "*"

然后,服务文件夹中的另一个serverless.yml使用公用文件上的属性

...

custom: ${file(../../serverless.common.yml):custom}
...
environment:
    stage: ${self:custom.stage}
...

这样,我可以毫无问题地访问自定义变量(从公共文件)。 现在,我想继续将此文件导入到自定义文件,但是要向其中添加与此服务相关的新变量,所以我尝试这样做:

custom: 
  common: ${file(../../serverless.common.yml):custom}
  wsgi:
    app: app.app
    packRequirements: false
  pythonRequirements:
    dockerizePip: non-linux

似乎可以访问,例如:

environment:
    stage: ${self:custom.common.stage}

但是现在,我收到了错误消息:

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

  A valid service attribute to satisfy the declaration 'self:custom.stage' Could not be found.


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

  A valid service attribute to satisfy the declaration 'self:custom.stage' Could not be found.


  Serverless Error ---------------------------------------

  Trying to populate non string value into a string for variable ${self:custom.stage}. Please make sure the value of the property is a strin

我在做什么错了?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)