env.dev

AWS Lambda Environment Variables: Console, CLI, SAM & CDK

How to set and manage environment variables in AWS Lambda. Covers the console, CLI, SAM templates, CDK, Terraform, KMS encryption, and Secrets Manager integration.

Last updated:

Loading…

Frequently Asked Questions

What is the size limit for Lambda environment variables?

AWS Lambda allows up to 4 KB total for all environment variables combined (keys + values). If you need more, store configuration in AWS Systems Manager Parameter Store or Secrets Manager and fetch it at runtime.

How do I encrypt Lambda environment variables?

Lambda encrypts all environment variables at rest with a default AWS KMS key. For additional security, use a customer-managed KMS key and encrypt sensitive values before deploying. Decrypt them at runtime using the AWS KMS SDK.

Should I use environment variables or Secrets Manager for Lambda?

Use environment variables for non-sensitive configuration (feature flags, API endpoints, region names). Use Secrets Manager or Parameter Store for sensitive data (API keys, database passwords) — they provide rotation, audit trails, and cross-account access.

Was this helpful?

Stay up to date

Get notified about new guides, tools, and cheatsheets.