@aws-sdk/client-kms
AWS SDK client for Key Management Service, providing Encrypt, Decrypt, and GenerateDataKey for envelope encryption.
Official Documentation ↗v3.658. Check the official docs for the latest API surface.Installation
npm install @aws-sdk/client-kmsMethods
No methods match this filter.
@aws-sdk/client-kms is aws sdk client for key management service, providing encrypt, decrypt, and generatedatakey for envelope encryption. This page documents the core methods, installation, and common usage patterns for the current stable release.
Installation
Install @aws-sdk/client-kms with your preferred package manager using the command shown in the frontmatter. The package is published to the npm registry and ships with TypeScript types where applicable.
Core methods
The methods listed in the frontmatter cover the primary API surface. Each signature reflects the v3.658 release. Consult the official documentation linked in sourceUrl for advanced options, edge cases, and breaking changes between major versions.
Frequently asked questions
The faq section in the frontmatter answers the most common questions about @aws-sdk/client-kms, including comparisons with alternatives, configuration tips, and runtime requirements. If your question is not covered, check the source URL for the full guide.
Errors
The official API reference declares the following error types:
InvalidCiphertextException(Throws 表:Fault=client) — official text: “InvalidCiphertextException | client | From the Decrypt or ReEncrypt operation, the request was rejected because the specified ciphertext, or additional authenticated data incorporated into the ciphertext, such as the encryption context, is corrupted, missing, “ (source: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/kms/command/DecryptCommand, fetched 2026-11-08T09:38:08.940Z)IncorrectKeyException(Throws 表:Fault=client) — official text: “IncorrectKeyException | client | The request was rejected because the specified KMS key cannot decrypt the data. The KeyId in a Decrypt request and the SourceKeyId in a ReEncrypt request must identify the same KMS key that was used to encrypt the ciphertext.” (source: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/kms/command/DecryptCommand, fetched 2026-11-08T09:38:08.940Z)InvalidKeyUsageException(Throws 表:Fault=client) — official text: “InvalidKeyUsageException | client | The request was rejected for one of the following reasons:” (source: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/kms/command/DecryptCommand, fetched 2026-11-08T09:38:08.940Z)DisabledException(Throws 表:Fault=client) — official text: “DisabledException | client | The request was rejected because the specified KMS key is not enabled.” (source: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/kms/command/DecryptCommand, fetched 2026-11-08T09:38:08.940Z)DependencyTimeoutException(Throws 表:Fault=server) — official text: “DependencyTimeoutException | server | The system timed out while trying to fulfill the request. You can retry the request.” (source: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/client/kms/command/DecryptCommand, fetched 2026-11-08T09:38:08.940Z)
Security
Official security statements captured from the package documentation:
- Decrypt 权限优先使用 key policy 而非 IAM policy;若必须用 IAM policy,应限定到具体 KMS key 或可信账号 — “Whenever possible, use key policies to give users permission to call the
Decryptoperation on a particular KMS key, instead of using IAM policies. Otherwise, you might create an IAM policy that gives the userDecryptpermission on all KMS keys. If you must use an IAM policy forDecryptpermiss” (source: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-kms/Class/DecryptCommand, fetched 2026-11-08T09:38:08.940Z) - 加密上下文(EncryptionContext)必须与解密时完全一致,否则解密失败 — “If you specify an
EncryptionContextwhen encrypting data, you must specify the same encryption context (a case-sensitive exact match) when decrypting the data. Otherwise, the request to decrypt fails with anInvalidCiphertextException.” (source: https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/Package/-aws-sdk-client-kms/Class/EncryptCommand, fetched 2026-11-08T09:38:08.940Z)
FAQ
- When to use GenerateDataKey?
- Use it for envelope encryption: encrypt large data locally with the plaintext key, store the encrypted key.
- What is the encrypt limit?
- 4 KB per Encrypt call; use GenerateDataKey for larger payloads.
- Does it support aliases?
- Yes. Pass an alias ARN as KeyId, e.g. alias/my-key.
Report a problem with this API docOpens a pre-filled issue on GitHub.