# How to make serverless not changing the value of environment variable?

**URL:** <https://forum.serverless.com/t/how-to-make-serverless-not-changing-the-value-of-environment-variable/6348>\
**Category:** Serverless Framework\
**Created:** [November 3, 2018, 10:32am UTC](https://forum.serverless.com/t/how-to-make-serverless-not-changing-the-value-of-environment-variable/6348 "2018-11-03T10:32:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![sergeda](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@sergeda](https://forum.serverless.com/u/sergeda)\
**Post date:** [November 3, 2018, 10:32am UTC](https://forum.serverless.com/t/how-to-make-serverless-not-changing-the-value-of-environment-variable/6348/1 "2018-11-03T10:32:37Z")

</div>

I’m trying to add environment variable to my function in Serverless config but set value for it using Lambda console to not store sensitive data in repository. The problem is: on every deployment of the function Serverless overrides value for the environment variable I set in console.  
I have no value for the variable in Serverless config, only the name.  
Is this possible to make it ignore value of variable?

---

<div class="post-metadata">

**Author:** ![buggy](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/buggy/32/177_2.png) [@buggy](https://forum.serverless.com/u/buggy)\
**Post date:** [November 5, 2018, 2:50am UTC](https://forum.serverless.com/t/how-to-make-serverless-not-changing-the-value-of-environment-variable/6348/2 "2018-11-05T02:50:38Z")

</div>

Have you tried removing the environment variable from the serverless.yml and just setting it in the console? Putting the name into the serverless config is like saying it’s value is an empty string.

---

<div class="post-metadata">

**Author:** ![sergeda](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@sergeda](https://forum.serverless.com/u/sergeda)\
**Post date:** [November 5, 2018, 5:31am UTC](https://forum.serverless.com/t/how-to-make-serverless-not-changing-the-value-of-environment-variable/6348/3 "2018-11-05T05:31:37Z")

</div>

I’m sure it will work but was hoping it’s possible to add variables using Serverless. Seems like it’s not.

---

<div class="post-metadata">

**Author:** ![garethmcc](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/garethmcc/32/2276_2.png) [@garethmcc](https://forum.serverless.com/u/garethmcc)\
**Post date:** [November 6, 2018, 6:35am UTC](https://forum.serverless.com/t/how-to-make-serverless-not-changing-the-value-of-environment-variable/6348/4 "2018-11-06T06:35:33Z")

</div>

In order to get around this type of issue, I use tools like Bitbucket Pipelines or Gitlab’s CI/CD runners to store data like this. You can add an environment variable to Bitbucket or Gitlab manually and reference that in your `serverless.yml` so that you end up using the environment variable you inserted into Bitbucket/Gitlab instead and never need to log into AWS to set it

---

<div class="post-metadata">

**Author:** ![sergeda](https://avatars.discourse-cdn.com/v4/letter/s/c68b51/32.png) [@sergeda](https://forum.serverless.com/u/sergeda)\
**Post date:** [November 6, 2018, 6:51am UTC](https://forum.serverless.com/t/how-to-make-serverless-not-changing-the-value-of-environment-variable/6348/5 "2018-11-06T06:51:18Z")

</div>

Great suggestion. Can you please show how can I reference that value in yml file?

---

<div class="post-metadata">

**Author:** ![garethmcc](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/garethmcc/32/2276_2.png) [@garethmcc](https://forum.serverless.com/u/garethmcc)\
**Post date:** [November 6, 2018, 10:06am UTC](https://forum.serverless.com/t/how-to-make-serverless-not-changing-the-value-of-environment-variable/6348/6 "2018-11-06T10:06:26Z")

</div>

What you do is set the environment variable in Bitbucket or Gitlab depending on which you use. Then in your serverless.yml you are referencing an environment variable so:

```auto
  environment:
    AN_ENV_VARIABLE_HERE: ${env:ENV_VAR_IN_BITBUCKET_OR_GITLAB}

```

Then when you deploy `AN_ENV_VARIABLE` will be available to your lambda with the value you used in your CI/CD build process.

Hope that’s clear enough.
