November 2, 2026 路 #47
The Lambda that carried its own keys
A Lambda reads from S3. Someone set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY as environment variables for an IAM user. What is the right change?
Next puzzle in UTC
One try. The first answer sticks.
How to fix it
Lambda already gets short-lived credentials from its execution role. Static keys add a long-lived secret that leaks through the console, state files, and logs.
Every Lambda runs with an execution role, and the runtime injects temporary credentials for it that rotate automatically. Long-lived IAM user keys in environment variables are visible to anyone with lambda:GetFunctionConfiguration, they land in Terraform or CloudFormation state, and they work from any laptop on earth until someone remembers to revoke them.
Encrypting the variables or rotating on a schedule shrinks the risk but keeps a secret you do not need. Putting keys in code is worse: now they are in git history.
Fix
{
"Effect": "Allow",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::reports-bucket/*"
}
Attach that policy to the execution role, remove both variables, deactivate and delete the keys, and check CloudTrail for any use of them from outside Lambda.