Doppler not injecting environment variables for Serverless framework deploys

After doing a doppler login just before the deploy with the command doppler run -- serverless deploy, the variables don’t seem to get injected and I am getting errors of the form Error: No xyz found on my Node.js 14 Lambda application.
I have tested this on local and the environment variables are injected correctly after running doppler run -- serverless offline start
Happy to provide any more details or test in a different way.

Hi Rnjai and welcome to the Doppler community!

Sorry you’re running into this issue. To help with troubleshooting, would you be able to log into the AWS Lambda Console to confirm that the environment variables have not been set?

If they haven’t, I’ll need to investigate further, but in the meantime, you could use our AWS Lambda docs which show you how to set environment variables for Lambda in a single command.

Hopefully, this unblocks you and I’ll reply back here once I’ve figured out why your doppler run -- serverless deploy command is not working.

Hey @ryan-blunden, thank you so much for the quick reply and the workaround. It will work great for the short term.
And I check the console and did not see the Doppler environment variables there. I did make a test with environment variables in the .env file and things showed up in the Lambda console

@ryan-blunden Is write access needed on the Doppler account to execute the short term solution you suggested -

doppler secrets upload --project lambda --config prd
<(aws lambda get-function-configuration --function-name doppler-test | jq .Environment.Variables)

[I changed project, config and function name and installed jq before running above command]
I got this error -

Unable to upload secrets
Doppler Error: You do not have write access.

Ok, thanks for checking the Lambda console environment variables Rnjai.

Sorry if this is not clear from the documentation, but this is only required if you have existing Lambda environment variables that you need to import into Doppler first. This is because the aws lambda update-function-configuration command replaces (not merges) the existing environment variables.

Hey again Rnjai,

I’ve been able to successfully set environment variables using doppler run -- serverless deploy so am wondering if it’s because of the syntax you’re using in your serverless.ym file.

In your function definition, are you using the ${env:} syntax? For example:

      API_KEY: ${env:API_KEY}