- Create or update a CloudWatch Log Group and set a retention period.
- Create a customer-managed KMS key in KMS.
- Update the KMS key policy so CloudWatch Logs can use the key.
- Associate the KMS key with the CloudWatch Log Group.
CloudWatch encrypts logs at rest by default. Attach a customer-managed KMS key only when you need to control key permissions, rotation, or deletion.
1) Configure log retention
Steps to set retention for an existing or new log group:- Open the AWS Console and navigate to CloudWatch.
- In the left-hand panel, go to Logs → Log groups (Log Management).
- Edit an existing log group’s retention (Select log group → Actions → Edit retention settings) or create a new log group.
LogGroup2 and set retention to 1 week (7 days). After the retention period expires, older log events are automatically deleted.

2) Create a customer-managed KMS key
To use your own KMS key for log encryption instead of the default AWS-managed key, create a customer-managed key in KMS and grant CloudWatch Logs permission to use it. Steps:- Open AWS Key Management Service (KMS) in the console.
- Choose Customer managed keys → Create key.
- Select a symmetric key and Key usage: Encrypt and decrypt.
- Provide an alias (for example
CWLogGroup) and a description. Optionally add tags. - In Key administrative permissions add the IAM user(s) or role(s) who should administer the key (for this demo we add the current IAM user).
- In Key usage permissions ensure the IAM user/role who will configure the CloudWatch log group can use the key (encrypt/decrypt, create grants).
- Edit the key policy to allow the CloudWatch Logs service principal in the target region to use the key (see next section).

3) KMS key policy: allow CloudWatch Logs to use the key
CloudWatch Logs needs explicit permission in the KMS key policy to perform KMS operations (for exampleDescribeKey, Encrypt, Decrypt, ReEncrypt*, GenerateDataKey*, CreateGrant). Without these permissions CloudWatch cannot encrypt log data with your customer-managed key.
Below is an example key policy that:
- Grants the account root full KMS permissions (typical initial default), and
- Grants the CloudWatch Logs service principal in
us-east-2permission to use the key.
Make sure the
Service principal in the policy matches the region of your log group (e.g., logs.us-east-2.amazonaws.com for Ohio). Also include the kms:GrantIsForAWSResource condition to restrict grants to AWS resources.- The CloudWatch Logs service principal is region-specific. Adjust to the region where the log group will be created (for example
logs.us-east-1.amazonaws.comorlogs.eu-west-1.amazonaws.com). - The
kms:GrantIsForAWSResourcecondition helps ensure only AWS services can use grants with this key. - Keep administrative access for trusted IAM users/roles so they can rotate keys, change the policy, or enable deletion protection as required.

4) Associate the KMS key with the CloudWatch Log Group
- Return to CloudWatch → Logs → Create log group (or edit an existing log group).
- In the Create log group form choose the KMS key ARN you created from the KMS key dropdown (or paste the ARN).
- Complete the creation or save changes.

These confirm:
- CloudWatch will automatically delete log events older than the configured retention, and
- Log events are encrypted using your customer-managed KMS key.
5) Final checks and troubleshooting
- If CloudWatch cannot encrypt logs, verify the KMS key policy includes the CloudWatch Logs service principal for the correct region and the required KMS actions.
- Ensure the IAM user or role managing the key has administrative permissions for the KMS key.
- If you move resources across regions, update the KMS key policy service principal to match the new region.
- Consider enabling key rotation and deletion protection for production keys to meet security and compliance requirements.