Somasundaram Sekar
Somasundaram Sekar

Reputation: 5524

Passing environment variables from command line

Is it possible to pass environment variable with sls deploy , sls doesn't seem to have switch like -e and the only possible way looks like having a seperate yaml file to manage variables and pass it on using "environment:" element in the serverless.yml file as mentioned in this article.

Upvotes: 5

Views: 4664

Answers (2)

Tomer
Tomer

Reputation: 400

You can use serverless parameters

Parameters can be passed directly via CLI --param flag, following the pattern --param="<key>=<value>":

serverless deploy --param="domain=myapp.com" --param="key=value"

Parameters can then be used via the ${param:XXX} variables:

provider:
  environment:
    APP_DOMAIN: ${param:domain}
    KEY: ${param:key}

https://www.serverless.com/framework/docs/guides/parameters

Upvotes: 5

John
John

Reputation: 41

You can use any arbitrary name for your environment variable and pass it to serverless.yml with:

serverless deploy --myEnvVar <value>

You reference this inside serverless.yml with:

environment:
  myLocalVar: ${opt:myEnvVar}

Upvotes: 4

Related Questions