Chapter 93: AWS Lambda and Serverless for DevOps
93.8 Configuration and secrets boundaries
Story (fictional teaching scenario). At a fictional Bhopal shop, Omar from Doha puts a database password in an example event. Kavya removes it: events and logs are not a secret store.
Why
Code, configuration and secrets have different lifetimes and exposure risks.
What
- Environment variable is a configuration string read by the process, such as a feature flag.
- Secret is a sensitive value that needs restricted access, rotation and safe retrieval.
- Secrets Manager is an AWS service for storing/retrieving secrets. Retrieval uses scoped role permissions, not hard-coded AWS access keys.
- Rotation replaces a secret; a cached value needs a refresh plan.
How
-
Keep ordinary settings in environment variables.
-
Keep sensitive values in a secret manager, not events, source or logs.
-
Retrieve only the required secret with least privilege.
-
Do not print values while debugging.
Example 1: Local nonsecret setting
- Read the input and the code.
import os
mode = os.environ.get('PRICE_MODE','standard')
print(mode)
- Read the result.
Output (illustrative; not executed on AWS)
standard
- What each part means:
os.environreads process configuration.getsupplies a default when unset. This example prints a harmless mode, never a password. Ordinary Lambda environment variables have a combined size limit; do not use them as bulk data storage.
Example 2: Secret reference, not its value
- Read the input and the code.
{"secret_reference":"training/database/read-only"}
- Read the result.
Output (illustrative; not executed on AWS)
Configuration contains a name. Logs contain neither the name’s retrieved value nor credentials.
- What each part means: The name is a fictional reference. Fetching it would require an approved real integration and role, which we do not perform. Encrypting values at rest does not prevent application code from leaking them into logs.
Ravindra Bagale's Tip
A secret hidden in the console can still leak through your code.
Console मध्ये लपलेलं secret code मधून leak होऊ शकतं.
Console में छिपा secret code से leak हो सकता है.
Did you understand? Let us try it once more.