# Serverless invoke local not setting environment variables for go function

**URL:** <https://forum.serverless.com/t/serverless-invoke-local-not-setting-environment-variables-for-go-function/7986>\
**Category:** Serverless Framework\
**Tags:** lambda\
**Created:** [April 13, 2019, 11:13pm UTC](https://forum.serverless.com/t/serverless-invoke-local-not-setting-environment-variables-for-go-function/7986 "2019-04-13T23:13:34Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gauntface](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gauntface/32/3230_2.png) [@gauntface](https://forum.serverless.com/u/gauntface)\
**Post date:** [April 13, 2019, 11:13pm UTC](https://forum.serverless.com/t/serverless-invoke-local-not-setting-environment-variables-for-go-function/7986/1 "2019-04-13T23:13:34Z")

</div>

I have a golang lambda function and it needs an environment variable to function and when running the function via `invoke local` it’s failing to receive the environment variables I set.

I’m invoking the function with the following command:

```auto
serverless invoke local \
		--function oauth \
		--data '{ "queryStringParameters": {"code":"<Example>"}}' \
		--env OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID} \
		--env OAUTH_CLIENT_SECRET=${OAUTH_CLIENT_SECRET}

```

But my function is simply not getting the environment variables. The logs from serverless are displaying the correct values, so I’m guessing I’m doing something wrong or the runtime isn’t receiving the values.

I do have these environment variables to be configured from ssm in my serverless.yml file:

```auto
    environment:
      OAUTH_CLIENT_ID: ${ssm:oauthClientID}
      OAUTH_CLIENT_SECRET: ${ssm:oauthClientSecret}

```

Any ideas?

I’m using serverless 1.40.0

---

<div class="post-metadata">

**Author:** ![moro](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/moro/32/4303_2.png) [@moro](https://forum.serverless.com/u/moro)\
**Post date:** [April 14, 2019, 2:05pm UTC](https://forum.serverless.com/t/serverless-invoke-local-not-setting-environment-variables-for-go-function/7986/2 "2019-04-14T14:05:48Z")

</div>

Hi, it seems to me that when you write `--env OAUTH_CLIENT_ID=${OAUTH_CLIENT_ID}` your `${OAUTH_CLIENT_ID}` refers to the terminal env variable, the terminal doesn’t have these variables that’s why OAUTH\_CLIENT\_ID and OAUTH\_CLIENT\_SECRET are empty.  
Can it be a problem?  
I’m using this plugin for such things [https://www.npmjs.com/package/serverless-dotenv-plugin](https://www.npmjs.com/package/serverless-dotenv-plugin).

---

<div class="post-metadata">

**Author:** ![gauntface](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/gauntface/32/3230_2.png) [@gauntface](https://forum.serverless.com/u/gauntface)\
**Post date:** [April 14, 2019, 3:05pm UTC](https://forum.serverless.com/t/serverless-invoke-local-not-setting-environment-variables-for-go-function/7986/3 "2019-04-14T15:05:19Z")

</div>

Thanks for the response.

The values are getting set correctly, serverless logs the full values from the terminal experts and I tried setting the values as plain strings to rule this out as an issue, the variables were still not getting set.

---

<div class="post-metadata">

**Author:** ![moro](https://yyz2.discourse-cdn.com/flex036/user_avatar/forum.serverless.com/moro/32/4303_2.png) [@moro](https://forum.serverless.com/u/moro)\
**Post date:** [April 14, 2019, 4:10pm UTC](https://forum.serverless.com/t/serverless-invoke-local-not-setting-environment-variables-for-go-function/7986/4 "2019-04-14T16:10:00Z")

</div>

I’ve tried to use an env param by myself - it works, but I use node.js (sls 1.40.0), maybe somebody who works with golang will help you.

p.s. I think it would be useful if you provide a serverless.yml + a piece of code where you try to use these variables
