Use dotenvx with AWS Lambda | dotenvx

Create the lambda handler in the language of your choice.

Install dotenvx into the lambda.

Add it to your lambda handler and place HELLO env in the body.

Add your .env file.

And encrypt it.

Zip everything up – making sure to ignore .env.keys.

On the next page, choose Upload from .zip File. And upload the function.zip you created earlier.

Click Test and you will see Hello encrypted:1234 in the body response.

Lastly, set the DOTENV_PRIVATE_KEY to decrypt your value at runtime. Click Add environment variables.

Set DOTENV_PRIVATE_KEY and its value from your .env.keys file.

After saving that, click Test and this time you will see Hello World in the body response.

You succesfully add encryption to your .env files. This is safer than scattering your secrets across third-party platforms and tools. When you need to update a secret, run dotenvx set KEY value and redeploy.

That's it! Distributing your lambdas is now much safer - as they only contain encrypted values.