Description
Lambda encrypts environment variables at rest by default. A customer managed KMS key gives you control over its policy and rotation.
Potential impact
Values written into serverless.yml remain visible to anyone who can read the file. Store secrets in a service such as Secrets Manager.
Remediation
To share a customer managed key across functions, set provider.kmsKeyArn. To select a key for one function, set its kmsKeyArn. Check permissions on each key you use.
Examples
hello uses the provider’s key, so you can omit its duplicate kmsKeyArn.
Before
yaml
provider:
name: aws
environment:
TABLE_NAME: tableName1
functions:
hello:
handler: handler.hello
environment:
TABLE_NAME: tableName2
After
yaml
provider:
name: aws
kmsKeyArn: arn:aws:kms:us-east-1:111122223333:key/12345678-1234-1234-1234-123456789012
environment:
TABLE_NAME: tableName1
functions:
hello:
handler: handler.hello
kmsKeyArn: arn:aws:kms:us-east-1:111122223333:key/12345678-1234-1234-1234-123456789012
environment:
TABLE_NAME: tableName2