For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-hardcoded-aws-access-key-in-lambda.md.
A documentation index is available at /llms.txt.
Lambda functions must not include hardcoded AWS access keys or secret access keys in environment variables because embedded credentials can be exposed via function configuration, logs, snapshots, or code and allow unauthorized access to other AWS resources.
This rule inspects AWS::Lambda::Function resources and verifies the Properties.Environment.Variables map does not contain values matching common AWS access key ID patterns (20 uppercase alphanumeric characters) or secret access key patterns (40 base64-like characters). Use IAM execution roles for permissions or store secrets in AWS Secrets Manager or AWS Systems Manager Parameter Store SecureString parameters and reference them from the function. Resources with environment variable values that match the access-key regex will be flagged.
Secure example using a Secrets Manager dynamic reference: