API Reference

@aws-sdk/client-kms

AWS SDK client for Key Management Service, providing Encrypt, Decrypt, and GenerateDataKey for envelope encryption.

Official Documentation ↗
CompatibilityThis documentation covers version v3.658. Check the official docs for the latest API surface.

Installation

npmnpm install @aws-sdk/client-kms

Methods

@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:

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 Decrypt operation on a particular KMS key, instead of using IAM policies. Otherwise, you might create an IAM policy that gives the user Decrypt permission on all KMS keys. If you must use an IAM policy for Decrypt permiss” (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 EncryptionContext when 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 an InvalidCiphertextException.” (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.