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-serverless-function-environment-variables-not-encrypted.md.
A documentation index is available at /llms.txt.
Serverless functions that define environment variables must encrypt those variables with a customer-managed AWS KMS key to protect secrets and configuration data from exposure if the function configuration is accessed or leaked. For AWS::Serverless::Function resources that include Properties.Environment.Variables, the Properties.KmsKeyArn property must be defined and set to a valid KMS key ARN or alias (not null). Resources missing KmsKeyArn or where KmsKeyArn is null will be flagged. Example secure configuration referencing a KMS key:
AWSTemplateFormatVersion:'2010-09-09'Transform:AWS::Serverless-2016-10-31Description:AWS SAM template with a simple API definitionResources:Function1:Type:AWS::Serverless::FunctionProperties:PackageType:ImageImageUri:account-id.dkr.ecr.region.amazonaws.com/ecr-repo-name:image-nameImageConfig:Command:- "app.lambda_handler"EntryPoint:- "entrypoint1"WorkingDirectory:"workDir"Tags:- Key:TypeValue:AWS Serverless FunctionDeadLetterConfig:TargetArn:arn:aws:sqs:us-east-1:2324243535:aaaType:SQSEnvironment:Variables:key:valueKmsKeyArn:arn:aws:kms:us-west-1:123456789123:key/12345678-12cc-45bb-98aa-9876543210cc
Non-Compliant Code Examples
AWSTemplateFormatVersion:'2010-09-09'Transform:AWS::Serverless-2016-10-31Description:AWS SAM template with a simple API definitionResources:Function:Type:AWS::Serverless::FunctionProperties:PackageType:ImageImageUri:account-id.dkr.ecr.region.amazonaws.com/ecr-repo-name:image-nameImageConfig:Command:- "app.lambda_handler"EntryPoint:- "entrypoint1"WorkingDirectory:"workDir"Tags:- Key:TypeValue:AWS Serverless FunctionDeadLetterConfig:TargetArn:arn:aws:sqs:us-east-1:2324243535:aaaType:SQSEnvironment:Variables:key:value
1
2
rulesets:- CloudFormation / AWS # Rules to enforce / AWS.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.