2

I am trying to set the serverless service name from the env file.

I have written it as

service: ${env:SERVICE_NAME}

It worked perfectly in previous versions of serverless framework. However since I upgraded it to the latest version, it has started throwing error stating

  The stack service name "${env:SERVICE_NAME}-dev" is not valid. A service name should only contain alphanumeric (case sensitive) and hyphens. It should start with an alphabetic character and shouldn't exceed 128 characters.

I have tried setting the service name manually and it works like charm. But the with env variable it stops working.

I have added all the plugins properly and the env variables works on different sections like resources and provider. It just not work in service name.

#serverless.yml

service: ${env:SERVICE_NAME}

plugins:
  - serverless-plugin-warmup
  - serverless-python-requirements
  - serverless-wsgi
  - serverless-dotenv-plugin
  - serverless-attach-managed-policy
  - serverless-api-gateway-caching
  • What is your serverless version? The plugin seems to be incompatible with serverless 3.x.x. https://github.com/neverendingqs/serverless-dotenv-plugin/discussions/155. – Register Sole Jan 20 '22 at 09:20
  • My serverless version is 2.72 @RegisterSole – Yatin Pandit Jan 20 '22 at 09:25
  • When deploying, serverless will print the list of env variables. Do you see `SERVICE_NAME`? Like `DOTENV: Loading environment variables from .env: Serverless: - SERVICE_NAME`. – Register Sole Jan 20 '22 at 09:30
  • Yeah.... it shows Serverless: DOTENV: Loading environment variables from .env: Serverless: - SERVICE_NAME – Yatin Pandit Jan 20 '22 at 09:40
  • Ok I'm using sls 2.69, and able to use env in the service name. Question, you mentioned you have written it as `service: ${env:SERVICE_NAME}`, but the error message has `dev` at the end (`${env:SERVICE_NAME}-dev`). Is it possible you are referring to a different serverless.yml? Or that the value inside `.env` file itself is `${env:SERVICE)NAME}-dev`? – Register Sole Jan 20 '22 at 09:45
  • Noo the value inside env is simply a string "teststage". And I have only 1 serverless through which I deploy it. What version of serverless-dotenv-plugin are you using? @RegisterSole – Yatin Pandit Jan 20 '22 at 10:05
  • My `serverless-dotenv-plugin` is `3.12.2` – Register Sole Jan 20 '22 at 10:09
  • I have the same one. Yet it fails for some reason :( – Yatin Pandit Jan 20 '22 at 10:34
  • Sorry my bad, my previous run was incorrect. I tried again, i got the same error with the `-dev` suffix, even though I don't have it in my config. – Register Sole Jan 20 '22 at 10:38

0 Answers0