Set environment variables from external file in serverless.yml

environment-variables, serverless-framework, yaml

Solution

From docs:

You can set the contents of an external file into a variable:

file: ${file(./serverless-env.yml)}

And later you can use this new variable to access the file variables.

secret: file.dev.SECRET

Or you can use the file directly:

secret: ${file(./serverless-env.yml):dev.SECRET}

Problem

I'm using serverless and serverless-local for local development. I've got an external file which holds references to environment variables which I retrieve from `node.env` in my app. From what I understand, I should be able to set my environment variables such as ``` dev: AWS_KEY: 'key', SECRET: 'secret test: AWS_KEY: 'test-key', SECRET: 'test-secret', etc: ... ``` and have those environment variables included in my app through the following line in my serverless.yml ``` provider: name: aws runtime: nodejs4.3 stage: ${opt:stage, self:custom.default_stage} deploymentBucket: serverless-deploy-packages/${opt:stage, self:custom.default_stage} environment: ${file(./serverless-env.yml):${opt:stage, self:custom.default_stage}} ``` then in the commandline, I call `serverless offline --stage dev --port 9000` I thought this would include the correct vars in my app, but it isn't working. Is this not how it is supposed to work? Am I doing something wrong here?

Original source