Get Amazon SNS notifications when the key state of an AWS KMS key changes
Shubham Harsora, Aromal Raj Jayarajan, Prasobh S P, and Vishnu Unnikrishnan, Amazon Web Services
Summary
When you delete an AWS Key Management Service (AWS KMS)
This pattern shows you how to monitor status changes to AWS KMS keys by using Amazon EventBridgeDisabled or PendingDeletion, and when a scheduled deletion completes. For example, if a user disables or schedules the deletion of an AWS KMS key, you receive an email notification with details about the change, such as the account, Region, caller, and key ID. If you receive a notification, you can re-enable the key or cancel the deletion before data is lost.
Prerequisites and limitations
Prerequisites
An active AWS account with an AWS Identity and Access Management (IAM) role or user that can create AWS CloudFormation stacks, AWS KMS keys, Amazon SNS topics, and Amazon EventBridge rules
An AWS KMS key
to use for testing AWS CloudTrail
turned on for management events (create a trail so that failed calls and a long history are available)
Limitations
The EventBridge rules are Regional. Deploy the stack in each AWS Region where you have AWS KMS keys.
The notifications for disabling a key and scheduling its deletion rely on CloudTrail management events. They usually arrive within a few minutes.
Failed requests (for example, a request that AWS KMS denies) also send a notification. The last line of the message shows the error code. The line is empty if the request succeeded.
The stack creates one AWS KMS key to encrypt the Amazon SNS topic. If you disable or delete that key, the notifications stop.
Architecture
Technology stack
AWS CloudFormation
AWS CloudTrail
Amazon EventBridge
AWS Key Management Service (AWS KMS)
Amazon Simple Notification Service (Amazon SNS)
Target architecture
The following diagram shows an architecture for building an automated monitoring and notification process for detecting any changes to the state of an AWS KMS key.

The diagram shows the following workflow:
A user disables an AWS KMS key or schedules its deletion. When the waiting period ends, AWS KMS deletes the key and sends a separate deletion event.
An EventBridge rule matches the event.
The EventBridge rule publishes a message to an Amazon SNS topic. The topic is encrypted with an AWS KMS customer managed key that the AWS CloudFormation stack creates.
Amazon SNS sends an email notification to the subscribed users.
You can customize the email message to meet your organization’s needs by changing the input transformer of each EventBridge rule. We recommend including information about the resources that use the AWS KMS key. This information helps users understand the impact of deleting the key.
Automation and scale
The AWS CloudFormation stack deploys all the necessary resources and services for this pattern to work. You can implement the pattern independently in a single account and Region, or deploy it to multiple accounts and Regions by using AWS CloudFormation StackSets
Tools
AWS CloudFormation
helps you set up AWS resources, provision them quickly and consistently, and manage them throughout their lifecycle across AWS accounts and AWS Regions. The CloudFormation template for this pattern describes all the AWS resources that you want, and CloudFormation provisions and configures those resources for you. Amazon EventBridge
is a serverless event bus service that helps you connect your applications with real-time data from a variety of sources. EventBridge delivers a stream of real-time data from your own applications and AWS services, and it routes that data to targets such as AWS Lambda . EventBridge simplifies the process of building event-driven architectures. AWS Key Management Service (AWS KMS)
helps you create and control cryptographic keys to help protect your data. Amazon Simple Notification Service (Amazon SNS)
helps you coordinate and manage the exchange of messages between publishers and clients, including web servers and email addresses. AWS CloudTrail
helps you enable operational and risk auditing, governance, and compliance of your AWS account. CloudTrail records actions taken by a user, role, or AWS service as events. The AWS KMS API calls that this pattern monitors are CloudTrail events.
Code
The code for this pattern is available in the GitHub Monitor AWS KMS keys disable and scheduled deletion
Epics
| Task | Description | Skills required |
|---|---|---|
Clone the repository. | Clone the GitHub Monitor AWS KMS keys disable and scheduled deletion
| AWS administrator, Cloud architect |
Deploy the AWS CloudFormation template. |
The stack shows | AWS administrator, Cloud architect |
| Task | Description | Skills required |
|---|---|---|
Confirm the subscription email. | After the CloudFormation template successfully deploys, Amazon SNS sends a subscription confirmation message to the email address that you entered. To receive notifications, you must confirm this email subscription. For more information, see Confirm the subscription | AWS administrator, Cloud architect |
| Task | Description | Skills required |
|---|---|---|
Disable an AWS KMS key. |
| AWS administrator |
Schedule the deletion of an AWS KMS key (optional). |
| AWS administrator |
Validate the subscription. | Confirm that you received the Amazon SNS notification email. The email arrives within a few minutes. It shows the account ID, Region, the caller, and the key ID. | AWS administrator |
| Task | Description | Skills required |
|---|---|---|
Delete the CloudFormation stack. |
The AWS KMS key that encrypts the topic goes into a pending deletion period (30 days by default) and is then removed. | AWS administrator |
Delete the test key. | If you created an AWS KMS key only for testing, schedule it for deletion in the AWS KMS console. | AWS administrator |
Related resources
AWS CloudFormation
(AWS documentation) Creating a stack on the AWS CloudFormation console
(AWS CloudFormation documentation) Building event-driven architectures on AWS
(AWS Workshop Studio documentation) AWS Key Management Service Best Practices
(AWS Whitepaper) Security best practices for AWS Key Management Service
(AWS KMS Developer Guide) Monitor KMS keys with Amazon EventBridge
(AWS KMS documentation) Enable compatibility between event sources from AWS services and encrypted topics
(Amazon SNS documentation) Detection and monitoring best practices for AWS KMS
(AWS Prescriptive Guidance) Monitor and remediate scheduled deletion of AWS KMS keys
(AWS Prescriptive Guidance)
Additional information
The Amazon SNS topic in this pattern is encrypted with a customer managed AWS KMS key that the AWS CloudFormation template creates. EventBridge can’t publish to a topic that uses the AWS managed key alias/aws/sns, because you can’t change that key’s policy. The customer managed key costs about USD 1 per month plus request charges. For more information, see AWS KMS pricing
Do not disable or delete the key that encrypts the topic. The rules in this stack also send a notification if that happens.