17

I was using serverless templates and all worked fine until suddenly all my deployments started ignoring .env files.

I searched through the documentation and it says that if I want to use the environment variables from .env files I now have to add useDotenv: true in my serverless.yml file. So I did:

app: xxx
org: xxx
useDotenv: true 

There was no effect.

My serverless.yml file contained nothing else before but the app and org variables.

Where do I need to add the seDotenv: true in order to make it read my .env variables?

Smlok
  • 598
  • 6
  • 19
  • 1
    It needs to go right in the same level where your `service` definition is, e.g. `service: my-service` then next line on that level add `useDotenv: true`. Which Serverless version are you using? – yvesonline Feb 18 '21 at 12:18
  • Thank you for your reply! The accepted answer is the one I was looking for. – Smlok Apr 05 '21 at 00:51

1 Answers1

22

You should put it at the root of your serverless.yml file.

I have mine just after the service attribute :

service: lb-courses
useDotenv: true
plugins:
  - serverless-offline
...
Eric Dofonsou
  • 236
  • 2
  • 2