5

I have a serverless.common.yml, with properties that should be shared by all the services, with that:

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: "*"

And, another serverless.yml inside a services folder, which uses properties on the common file:

...

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

In that way, I can access the custom variables (from the common file) without a problem. Now, I want to continue to import this file to custom, but adding new variables, related to this service, to it, so I tried that:

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

And it seems it's possible to access, for example:

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

But now, I'm receiving the error:

 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

What am I doing wrong?

1 Answer 1

0

In your serverless.common.yml you must reference as if it were serverless.yml. In this case ${self:custom.stage} does not exist, but ${self:custom.common.stage} does exist.

service: ixxxx
custom:
  stage: ${opt:stage, self:provider.stage}
  resourcesStages:
    prod: prod
    dev: dev
  resourcesStage: ${self:custom.common.resourcesStages.${self:custom.common.stage}, self:custom.resourcesStages.dev}

lambdaPolicyXRay:
  Effect: Allow
  Action:
    - xray:PutTraceSegments
    - xray:PutTelemetryRecords
  Resource: "*"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.