Serverless invoke local not setting environment variables for go function

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:

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:

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

Any ideas?

I’m using serverless 1.40.0

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.

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.

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