Exposed secrets in Lambda function environment variables High

The exposure of secrets through Lambda function's environment variables is detected. Make sure that secrets are not exposed by environment variables of Lambda function.

Detector ID
cloudformation/exposed-lambda-env-secret-cloudformation@v1.0
Category
Common Weakness Enumeration (CWE) external icon

Noncompliant example

1Resources:
2  Resource:
3    Type: "AWS::Lambda::Function"
4    Properties:
5      Description: AWS Lambda Function to initiate the chat with the end user
6      Handler: "index.handler"
7      Role: !GetAtt InitiateChatLambdaExecutionRole.Arn
8      Runtime: "nodejs14.x"
9      MemorySize: 128
10      Timeout: 30
11      Environment:
12        # Noncompliant: hard-coded secrets exist in lambda environment.
13        Variables:
14          key1: AKIAAAAAAAAAAAAAAAAA
15      Code:
16        S3Bucket: !Ref SourceBucket
17        S3Key: !Ref InitiateChatLambdaCodeObject
18      ReservedConcurrentExecutions: 100
19      DeadLetterConfig:
20        TargetArn: "test"
21      VpcConfig:
22        SecurityGroupIds:
23          - sg-12345
24        SubnetIds:
25          - subnet-12345
26          - subnet-67890
27      KmsKeyArn: arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab

Compliant example

1Resources:
2  Resource:
3    Type: "AWS::Lambda::Function"
4    Properties:
5      Description: AWS Lambda Function to initiate the chat with the end user
6      Handler: "index.handler"
7      Role: !GetAtt InitiateChatLambdaExecutionRole.Arn
8      Runtime: "nodejs14.x"
9      MemorySize: 128
10      Timeout: 30
11      Environment:
12        # Compliant: no hard-coded secrets exist in lambda environment.
13        Variables:
14          key1: not_a_secret
15      Code:
16        S3Bucket: !Ref SourceBucket
17        S3Key: !Ref InitiateChatLambdaCodeObject
18      ReservedConcurrentExecutions: 100
19      DeadLetterConfig:
20        TargetArn: "test"
21      VpcConfig:
22        SecurityGroupIds:
23          - sg-12345
24        SubnetIds:
25          - subnet-12345
26          - subnet-67890
27      KmsKeyArn: arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab