Customer managed key not specified for SAM function environment variables

Specify a customer managed KMS key when a SAM function requires separate key control.

Description

Lambda encrypts environment variables at rest by default. You can choose the key it uses.

Potential impact

A customer managed key lets you control who can use the key and when it rotates.

Remediation

If you need a customer managed key, set KmsKeyArn to its ARN and check its permissions. Keep secrets in a service such as Secrets Manager. Values written in a template remain visible in the source.

Examples

example-token is a placeholder. Supply the image URI when deploying this function.

Before

yaml
Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      Environment:
        Variables:
          API_TOKEN: example-token

After

yaml
Resources:
  Function:
    Type: AWS::Serverless::Function
    Properties:
      PackageType: Image
      Environment:
        Variables:
          API_TOKEN: example-token
      KmsKeyArn: arn:aws:kms:ap-northeast-2:123456789012:key/12345678-1234-1234-1234-123456789012

References