Post Syndicated from Jeremy Stieglitz original https://aws.amazon.com/blogs/security/how-to-use-on-demand-rotation-for-aws-kms-imported-keys/
Today, we’re announcing support for on-demand rotation of symmetric encryption AWS Key Management Service (AWS KMS) keys with imported key material (EXTERNAL origin). This new capability enables you to rotate the cryptographic key material of these keys without changing the key identifier (key ID or Amazon Resource Name (ARN)). Rotating keys helps you meet compliance requirements and security best practices that mandate periodic key rotation.
AWS KMS has long supported automatic key rotation for AWS KMS keys whose key material is generated by AWS KMS (AWS_KMS origin). Until now, AWS KMS customers who imported their own key material could not rotate that material without creating a new KMS key. This process called manual rotation required updating references to the older key identifiers. With today’s launch, the key ID of the imported key remains unchanged after rotation, so existing workloads are not disrupted. In this post, we tell you how the new capability works, look at key material expiry and deletion features unique to imported keys, and review pricing for this new feature.
How it works
When you create an AWS KMS key with EXTERNAL origin, AWS KMS assigns a fixed identifier to the key called the key ID. However, AWS KMS doesn’t generate key material for the cryptographic operations. You must import your own key material using the ImportKeyMaterial operation.
When you import key material, AWS KMS computes a unique key material identifier based on the key ID and the key material. Even if you import the same key material in different keys, AWS KMS will assign distinct key material identifiers. This computation uses a cryptographic hash so the key material identifier doesn’t reveal information about the key material itself. AWS KMS embeds this key material identifier in the ciphertext blob produced by symmetric encryption.
Until now, after you imported key material into an AWS KMS key, you could not import additional key material into that key to rotate the key. With this new feature launch, you can associate multiple imported key materials with a single, symmetric-encryption key. You can use the RotateKeyOnDemand operation to make the most recently imported key material the current key material. AWS KMS uses the current key material to generate new ciphertext. Unless deleted or expired, the other key materials remain available for decryption. When you present ciphertext for decryption, AWS KMS automatically selects the correct key material using the key material identifier embedded in the ciphertext.
To help improve the auditability that keys have rotated, we’ve added new identifiers in KMS API responses for the specific key material used. The KeyMaterialId is a new field that AWS KMS will return in addition to the KeyId. Similarly, the DescribeKey response for these keys now displays the identifier of the current key material as CurrentKeyMaterialId. The inclusion of the KeyMaterialId and CurrentKeyMaterialId in API responses makes key rotation more transparent.
Before we dive into the details, the following is an outline of the overall process to rotate an imported key:
- Create a symmetric encryption KMS key with
EXTERNALorigin - Import key material into the key using GetParametersForImport and ImportKeyMaterial APIs. The first key material becomes usable immediately. This part is unchanged and maintains backwards compatibility with the current behavior of AWS KMS.
- Use the key to create ciphertext and decrypt it. You’ll notice the key material ID matches the
CurrentKeyMaterialIddisplayed in the DescribeKey response. - When you want to rotate this key, import a second key material into the key. The ImportKeyMaterial API now has a new
ImportTypeinput parameter which lets you inform AWS KMS whether you are associating new key material with a key (--import-type NEW_KEY_MATERIAL) or re-importing previously associated key material (--import-type EXISTING_KEY_MATERIAL). - Use ListKeyRotations with
--include-key-material ALL_KEY_MATERIALto view both key materials. The key material state of the second key material will bePENDING_ROTATION. - Use the RotateKeyOnDemand operation to initiate on-demand key rotation.
- Optionally, you can use the GetKeyRotationStatus operation to monitor the in-progress rotation. The response will contain
OnDemandRotationStartDateonly while the rotation is in progress. - Use
ListKeyRotationswith--include-key-material ALL_KEY_MATERIALafter rotation completes to view key materials associated with this key. TheKeyMaterialStateof the new key material you imported will change fromPENDING_ROTATIONtoCURRENT. The key material state of the first key material will change fromCURRENTtoNON_CURRENT. - Use the key to create ciphertext and decrypt it. You’ll notice the
CurrentKeyMaterialIdis used for creating ciphertext, but the key material used for decryption is automatically determined by AWS KMS.
Using the AWS CLI for rotating an imported key
The following is a sample sequence of AWS KMS commands to exercise the import key rotation functionality using the AWS Command Line Interface (AWS CLI). The specific commands that follow work in Linux or MacOS environments and might need to be modified for use in a Windows environment. This functionality can also be exercised through the AWS SDKs. These operations, except for wrapping a key material for import, generate-data-key, and decrypt can be initiated in the AWS Management Console.
Step 1: Create a key and import key material
This section should be familiar to anyone who has used the existing import key functionality in AWS KMS.
- Create a symmetric encryption key with
EXTERNALorigin and save the key ARN. The initial state of this key isPendingImport. - Generate a 256-bit (32-byte) key material to be imported. In the following command, we use OpenSSL to generate the imported key material.
- Use the
get-parameters-for-importcommand to create the wrapping key and import token and save them to files. AWS KMS supports multiple wrapping algorithms; we useRSAES_OAEP_SHA_256with a 4096-bit RSA key in the following example. The value of theImportTokenandPublicKeyfields in the response has been trimmed for brevity. - Wrap the key material using the wrapping key. We use OpenSSL, a popular open source cryptographic library to illustrate this step. For a detailed explanation of this step, see the AWS KMS Developer Guide.
- Import the key material. Optionally, you can assign a key material description. The description can be used to keep track of where the key material is durably maintained outside AWS KMS. This key material description is displayed alongside other information for this key material in the console and the
ListKeyRotationsAPI response. We also capture the key material ID from the response. In this example, the key material doesn’t expire. Optionally, you can set an expiration time. - The key is now be enabled for use in cryptographic operations and the
CurrentKeyMaterialIdin theDescribeKeyresponse should match${KEY_MATERIAL1_ID} - Use
ListKeyRotationsto view key materials associated with the key. There should only be one key material with the same ID as in${KEY_MATERIAL1_ID}and with a key material state ofCURRENT.
Step 2: Use the first key material to create and decrypt ciphertext
This step demonstrates how to verify the key material ID of your imported key in cryptographic operations.
- Use the
GenerateDataKeyoperation and capture the ciphertext. This operation returns a data key in both plaintext and ciphertext form. TheKeyMaterialIdin the response matches the identifier for the first key material. - Decrypt the ciphertext and compare it to the plaintext key. The
KeyMaterialIdin the response matches the identifier for the first key material. The plaintext in decrypt response matches the plaintext data key in theGenerateDataKeyresponse.
Step 3: Import a second key material into the key for on-demand rotation
Import key rotations start with importing new key material into this key.
- Generate a second key material (also 256 bits in length).
- Use the
get-parameters-for-importcommand to create the wrapping key and import token for the second key material to be imported. The value of theImportTokenandPublicKeyfields in the response has been trimmed for brevity. - Wrap the second key material using the wrapping key.
- Import the second key material. Optionally, you can assign a key material description. We also capture the key material ID from the response. In this example, the key material doesn’t expire. Optionally, you can set an expiration time.
Note: This call will fail if you omit the
import-type parameteror set it toEXISTING_KEY_MATERIAL. Specifyingimport-typeasNEW_KEY_MATERIALallows the API caller to associate additional key material with the imported key. - Use
ListKeyRotationsto view key materials associated with the key. There should now be two key materials. The key material state of the second key material should bePENDING_ROTATION. - The
CurrentKeyMaterialIdinDescribeKeyresponse should still be${KEY_MATERIAL1_ID}.
Step 4: Use on-demand rotation to update the current key material
This step moves the current key material for this key to the newly imported key material.
- Use the
RotateKeyOnDemandoperation to initiate an on-demand key rotation. If the key material inPENDING_ROTATIONstate is deleted or expires before initiating on-demand rotation, this operation will fail. - AWS KMS uses a background worker to perform the rotation, so there’s a delay between initiating the on-demand key rotation and its completion. Use the
GetKeyRotationStatuscommand to monitor the rotation status. Until the rotation is completed, theGetKeyRotationStatusresponse will include theOnDemandRotationStartDatefield. When this field disappears, the on-demand key rotation is complete. - Use
ListKeyRotationswhen rotation completes. The second key material changes state fromPENDING_ROTATIONtoCURRENT. - Rotation changes the current key material, which is reflected in the
CurrentKeymaterialIdfield in theDescribeKeyresponse. It should now match${KEY_MATERIAL2_ID}.
Step 5: Use the second key material to create and decrypt ciphertext
Similar to Step 2, this step demonstrates how to verify that the key material ID of your imported key in cryptographic operations has been rotated.
- Use the
GenerateDataKeyoperation and capture the ciphertext. This operation returns a data key in both plaintext and ciphertext forms. Note that theKeyMaterialIdreturned in the response matches the identifier of the second key material. - Decrypt the ciphertext and compare it to the plaintext key. The
KeyMaterialIdreturned in the response matches the identifier of the second key material. The plaintext in decrypt response matches the plaintext data key in the previousGenerateDataKeyresponse. - AWS KMS automatically uses the correct key material based on the ciphertext. When you decrypt the ciphertext produced in Step 2, AWS KMS uses the first key material.
Step 6: Delete key material, make the key unusable
With the launch of this feature, the DeleteImportedKeyMaterial operation takes an optional KeyMaterialId parameter. If no KeyMaterialId is specified, AWS KMS deletes the current key material. This maintains backwards compatibility with existing behavior.
- Delete the first imported key material by specifying its identifier.
- Deleting the key material causes the key state to change to
PendingImport. ListKeyRotationsalso reflects the first key material asPendingImport.- Cryptographic operations fail with a
KMSInvalidStateExceptionwhen a key is inPendingImportstate even though the key material required to decrypt the specific ciphertext blob is imported into AWS KMS.
Step 7: Reimport key material to enable the key
You need to re-import all expired or deleted key materials associated with a key for the key to become usable again.
- Re-import the missing key material. For this example, we reused the wrapped key and import token we already have. This is an optimization. Optionally, you can get new parameters for wrapping and importing the key material.
- Use
DescribeKeyto validate the key is now enabled. - You can use the following commands to validate that the key works:
CloudTrail logging
AWS CloudTrail now includes the key material ID in the additionalEventData field for operations using symmetric-encryption keys (both AWS_KMS and EXTERNAL origin). The following is a sample CloudTrail event for the AWS KMS decrypt operation:
Key expiry and key deletion capabilities unique to imported keys
Unlike standard KMS keys that you create within AWS KMS, imported keys offer two unique capabilities for enhanced controls over key material within AWS.
- When importing key material into a KMS key, you can optionally set an expiration date and time, up to 365 days from the import date. If you don’t specify an expiration, the key material doesn’t expire. When the expiration time is reached, AWS KMS immediately deletes the key material and the KMS key becomes unusable. This is in contrast to the 7–30 day waiting period required for KMS keys whose key material is generated by AWS KMS. To re-enable the key, you must reimport the key material. With key rotation, you can continue to set expiration periods for new key material that you import.
- Unique to KMS imported keys, you can also delete specific key material without deleting the entire KMS key. Deleting the key material of a KMS imported key is temporary and reversible. To restore the key, reimport its key material.
Key expiry and import key material deletion can be useful if you need to demonstrate immediate key suspension in the cloud or when you want to temporarily seed AWS KMS with key material that can be inserted and repeatedly removed from cloud access (hydration and re-hydration of keys for improved digital sovereignty).
Special considerations
AWS KMS is designed to keep imported key material highly available. But AWS KMS doesn’t maintain the durability of imported key material at the same level as key material that AWS KMS generates. You must retain a copy of the imported key material outside of AWS KMS in a system that you control. We recommend that you store an exportable copy of the imported key material in a key management system, such as an HSM. As a best practice, you should store a reference to the KMS key ARN and key material description alongside the exportable copy of the key material.
The deletion or expiration of any key material associated with a KMS key makes that key unusable. You must re-import all the key materials associated with a key before it can be used for cryptographic operations.
The following types of KMS keys with imported key material do not support on-demand key rotation, but you can continue to use manual rotation with these keys.
- Asymmetric keys
- HMAC keys
- Multi-AWS Region keys
Features and benefits
This new capability includes several important features:
- Maintain key identifiers: Rotate key material while keeping the same AWS KMS key ID and ARN.
- Flexible rotation: Rotate keys on-demand to meet your security requirements or use an external key manager to set a rotation schedule that can drive new key rotations into AWS KMS.
- Audit trail: Track key material usage through CloudTrail logs.
- Metadata management: Add unique descriptions to each key material version.
- Retains support for key expiry and import key deletion (features unique to KMS imported keys)
Pricing
For AWS KMS keys that rotate automatically or on-demand, each key incurs a base cost, and the first two rotations add $1 per month (prorated hourly) in additional charges. The pricing is capped after the second rotation, meaning subsequent rotations beyond the second one aren’t billed. This simplified pricing provides you with more predictable costs while maintaining the flexibility to rotate keys frequently to meet your compliance and security audit requirements.
Getting started
You can start using this feature today in all AWS Regions where AWS KMS is available. To learn more, visit the AWS KMS Developer Guide.
We’re excited to see how you use this new capability to enhance your key management practices. Leave a comment below or on the AWS re:Post community forum to let us know what you think.


























Dhrubajyoti Mukherjee is a Cloud Infrastructure Architect with a strong focus on data strategy, data governance, and artificial intelligence at Amazon Web Services (AWS). He uses his deep expertise to provide guidance to global enterprise customers across industries, helping them build scalable and secure cloud solutions that drive meaningful business outcomes. Dhrubajyoti is passionate about creating innovative, customer-centric solutions that enable digital transformation, business agility, and performance improvement. Outside of work, Dhrubajyoti enjoys spending quality time with his family and exploring nature through his love of hiking mountains.



































Satesh Sonti is a Sr. Analytics Specialist Solutions Architect based out of Atlanta, specializing in building enterprise data platforms, data warehousing, and analytics solutions. He has over 19 years of experience in building data assets and leading complex data platform programs for banking and insurance clients across the globe.
Jonathan Katz is a Principal Product Manager – Technical on the Amazon Redshift team and is based in New York. He is a Core Team member of the open source PostgreSQL project and an active open source contributor, including PostgreSQL and the pgvector project.
Asena Uyar is a Software Engineer at LaunchDarkly, focusing on building impactful experimentation products that empower teams to make better decisions. With a background in mathematics, industrial engineering, and data science, Asena has been working in the tech industry for over a decade. Her experience spans various sectors, including SaaS and logistics, and she has spent a significant portion of her career as a Data Platform Engineer, designing and managing large-scale data systems. Asena is passionate about using technology to simplify and optimize workflows, making a real difference in the way teams operate.
Dean Verhey is a Data Platform Engineer at LaunchDarkly based in Seattle. He’s worked all across data at LaunchDarkly, ranging from internal batch reporting stacks to streaming pipelines powering product features like experimentation and flag usage charts. Prior to LaunchDarkly, he worked in data engineering for a variety of companies, including procurement SaaS, travel startups, and fire/EMS records management. When he’s not working, you can often find him in the mountains skiing.
Daniel Lopes is a Solutions Architect for ISVs at AWS. His focus is on enabling ISVs to design and build their products in alignment with their business goals with all advantages AWS services can provide them. His areas of interest are event-driven architectures, serverless computing, and generative AI. Outside work, Daniel mentors his kids in video games and pop culture.












Sachin Kale is a senior software development engineer at AWS working on OpenSearch.
Bukhtawar Khan is a Principal Engineer working on Amazon OpenSearch Service. He is interested in building distributed and autonomous systems. He is a maintainer and an active contributor to OpenSearch.
Gaurav Bafna is a Senior Software Engineer working on OpenSearch at Amazon Web Services. He is fascinated about solving problems in distributed systems. He is a maintainer and an active contributor to OpenSearch.





















Vetri Natarajan is a Specialist Solutions Architect for Amazon QuickSight. Vetri has 15 years of experience implementing enterprise business intelligence (BI) solutions and greenfield data products. Vetri specializes in integration of BI solutions with business applications and enable data-driven decisions.
Ismael Murillo is a Solutions Architect for Amazon QuickSight. Before joining AWS, Ismael worked in Amazon Logistics (AMZL) with delivery station management, delivery service providers, and our customer actively in the field. Ismael focused on last mile delivery and delivery success. He designed and implemented many innovative solutions to help reduce cost, influence delivery success. He is also a United States Army Veteran, where he served for eleven years.



















