Skip to main content
In this lesson you’ll learn how to configure custom CloudWatch Logs retention and attach a customer-managed AWS KMS key to a CloudWatch Log Group. This gives you control over how long logs are retained and which KMS key is used to encrypt them, enabling stricter access controls and key lifecycle management. What you’ll do:
  • 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 Logs are encrypted at rest by default. Use a customer-managed KMS key when you need control over key rotation, deletion, or fine-grained key permissions.
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:
  1. Open the AWS Console and navigate to CloudWatch.
  2. In the left-hand panel, go to Logs → Log groups (Log Management).
  3. Edit an existing log group’s retention (Select log group → Actions → Edit retention settings) or create a new log group.
When creating a new log group, choose a retention period that satisfies operational and compliance needs. In this demo we create a log group named LogGroup2 and set retention to 1 week (7 days). After the retention period expires, older log events are automatically deleted.
Screenshot of the AWS CloudWatch "Create log group" page showing form fields — Log group name set to "LogGroup2", retention set to 1 week, and Log class "Standard". The AWS console header and navigation are visible at the top.

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:
  1. Open AWS Key Management Service (KMS) in the console.
  2. Choose Customer managed keys → Create key.
  3. Select a symmetric key and Key usage: Encrypt and decrypt.
  4. Provide an alias (for example CWLogGroup) and a description. Optionally add tags.
  5. 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).
  6. In Key usage permissions ensure the IAM user/role who will configure the CloudWatch log group can use the key (encrypt/decrypt, create grants).
  7. Edit the key policy to allow the CloudWatch Logs service principal in the target region to use the key (see next section).
Screenshot of the AWS KMS "Create key" console showing the "Key usage" options with "Encrypt and decrypt" selected. The left sidebar shows the step-by-step setup (define permissions, key policy) and the browser UI/organization name is visible at the top.

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 example DescribeKey, 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-2 permission to use the key.
Replace the account ID, region, and other identifiers as needed for your environment.
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.
Notes about this policy:
  • 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.com or logs.eu-west-1.amazonaws.com).
  • The kms:GrantIsForAWSResource condition 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.
After creating the key you should see it listed and enabled in the KMS console.
A screenshot of the AWS KMS "Customer managed keys" console showing a table of key aliases, key IDs, statuses (e.g., Pending deletion, Enabled), key type/spec and usage. The page includes a search/filter bar plus "Key actions" and "Create key" buttons.

4) Associate the KMS key with the CloudWatch Log Group

  1. Return to CloudWatch → Logs → Create log group (or edit an existing log group).
  2. In the Create log group form choose the KMS key ARN you created from the KMS key dropdown (or paste the ARN).
  3. Complete the creation or save changes.
Screenshot of the AWS CloudWatch console on the "Create log group" page. The KMS key ARN dropdown is expanded showing several key IDs and a "Create an AWS KMS key" button.
Once created, open the log group details and verify both settings: the retention period and the KMS key ARN assigned to the log group. Quick reference — Example Log Group details you’ll see in the console: 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.
Congratulations — you’ve configured custom log retention and attached a customer-managed KMS key to a CloudWatch Log Group.

Watch Video