Securing Sensitive Data in AWS Lambda
Instruction: Discuss best practices for securing sensitive data within AWS Lambda functions.
Updated
Official answer
Identify which values are sensitive, where they enter the function, and every place they can be copied: events, temporary files, logs, traces, failure destinations and downstream stores.
For a database password, put the secret in Secrets Manager and keep its identifier in configuration. Give the execution role access to the required secret and, where applicable, its encryption key. Retrieve it through an approved client or extension, and test rotation and cache refresh. Environment-variable encryption at rest does not prevent authorized code from reading plaintext; AWS recommends a secret store for credentials and API keys.
Minimize payloads and use authenticated TLS connections. Apply the receiving service's access and encryption controls. Redact sensitive fields before logging, protect log access, and set retention deliberately. A dead-letter queue can contain the original sensitive event and needs equivalent controls.
Do not retain one user's sensitive data in reusable globals or temporary files for another invocation. Environment reuse is possible; use request-scoped state and a deliberate cleanup policy. Configure the required CloudTrail invocation data events and application audit records; ordinary function logging is not proof that all activity was captured.
Verify denied secret access, rotation, malformed input and redaction with synthetic data. Document what remains available to privileged operators or compromised function code.