AWS Builder Center

How I keep a secret out of a Lambda deployment package

Secrets do not belong in a deployment zip. Here is the small set of checks I run before a deploy.

Full-stack Developer & Security Researcher
Secrets never go in the deployment zip. The zip holds code and dependencies, nothing else.
Use environment variables for non-sensitive config only. Real secrets go in Secrets Manager or Parameter Store. The function fetches them at runtime, and the role can read only that one secret.
Check the zip before deploy. Run unzip -l and grep for keys, tokens, and .env files. Keep local .env out of git with .gitignore.
If a secret leaks, rotate it first. Then fix the code.
Any opinions in this article are those of the individual author and may not reflect the opinions of AWS.
Enjoyed reading this content? Let the author know!

Your likes, comments, shares, and saves help creators reach more builders.

Loading recommendations

Loading article