clients/client-kms/README.md
AWS SDK for JavaScript KMS Client for Node.js, Browser and React Native.
<fullname>Key Management Service</fullname>
<p>Key Management Service (KMS) is an encryption and key management web service. This guide describes the KMS operations that you can call programmatically. For general information about KMS, see the <a href="https://docs.aws.amazon.com/kms/latest/developerguide/"> <i>Key Management Service Developer Guide</i> </a>.</p> <note> <p>KMS has replaced the term <i>customer master key (CMK)</i> with <i>Key Management Service key</i> and <i>KMS key</i>. The concept has not changed. To prevent breaking changes, KMS is keeping some variations of this term.</p> <p>Amazon Web Services provides SDKs that consist of libraries and sample code for various programming languages and platforms (Java, Rust, Python, Ruby, .Net, macOS, Android, etc.). The SDKs provide a convenient way to create programmatic access to KMS and other Amazon Web Services services. For example, the SDKs take care of tasks such as signing requests (see below), managing errors, and retrying requests automatically. For more information about the Amazon Web Services SDKs, including how to download and install them, see <a href="http://aws.amazon.com/tools/">Tools for Amazon Web Services</a>.</p> </note> <p>We recommend that you use the Amazon Web Services SDKs to make programmatic API calls to KMS.</p> <p>If you need to use FIPS 140-2 validated cryptographic modules when communicating with Amazon Web Services, use one of the FIPS endpoints in your preferred Amazon Web Services Region. If you need communicate over IPv6, use the dual-stack endpoint in your preferred Amazon Web Services Region. For more information see <a href="https://docs.aws.amazon.com/general/latest/gr/kms.html#kms_region">Service endpoints</a> in the Key Management Service topic of the <i>Amazon Web Services General Reference</i> and <a href="https://docs.aws.amazon.com/kms/latest/developerguide/ipv6-kms.html">Dual-stack endpoint support</a> in the KMS Developer Guide.</p> <p>All KMS API calls must be signed and be transmitted using Transport Layer Security (TLS). KMS recommends you always use the latest supported TLS version. Clients must also support cipher suites with Perfect Forward Secrecy (PFS) such as Ephemeral Diffie-Hellman (DHE) or Elliptic Curve Ephemeral Diffie-Hellman (ECDHE). Most modern systems such as Java 7 and later support these modes.</p> <p> <b>Signing Requests</b> </p> <p>Requests must be signed using an access key ID and a secret access key. We strongly recommend that you do not use your Amazon Web Services account root access key ID and secret access key for everyday work. You can use the access key ID and secret access key for an IAM user or you can use the Security Token Service (STS) to generate temporary security credentials and use those to sign requests. </p> <p>All KMS requests must be signed with <a href="https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html">Signature Version 4</a>.</p> <p> <b>Logging API Requests</b> </p> <p>KMS supports CloudTrail, a service that logs Amazon Web Services API calls and related events for your Amazon Web Services account and delivers them to an Amazon S3 bucket that you specify. By using the information collected by CloudTrail, you can determine what requests were made to KMS, who made the request, when it was made, and so on. To learn more about CloudTrail, including how to turn it on and find your log files, see the <a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/">CloudTrail User Guide</a>.</p> <p> <b>Additional Resources</b> </p> <p>For more information about credentials and request signing, see the following:</p> <ul> <li> <p> <a href="https://docs.aws.amazon.com/general/latest/gr/aws-security-credentials.html">Amazon Web Services Security Credentials</a> - This topic provides general information about the types of credentials used to access Amazon Web Services.</p> </li> <li> <p> <a href="https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp.html">Temporary Security Credentials</a> - This section of the <i>IAM User Guide</i> describes how to create and use temporary security credentials.</p> </li> <li> <p> <a href="https://docs.aws.amazon.com/general/latest/gr/signature-version-4.html">Signature Version 4 Signing Process</a> - This set of topics walks you through the process of signing a request using an access key ID and a secret access key.</p> </li> </ul> <p> <b>Commonly Used API Operations</b> </p> <p>Of the API operations discussed in this guide, the following will prove the most useful for most applications. You will likely perform operations other than these, such as creating keys and assigning policies, by using the console.</p> <ul> <li> <p> <a>Encrypt</a> </p> </li> <li> <p> <a>Decrypt</a> </p> </li> <li> <p> <a>GenerateDataKey</a> </p> </li> <li> <p> <a>GenerateDataKeyWithoutPlaintext</a> </p> </li> </ul>To install this package, use the CLI of your favorite package manager:
npm install @aws-sdk/client-kmsyarn add @aws-sdk/client-kmspnpm add @aws-sdk/client-kmsThe AWS SDK is modulized by clients and commands.
To send a request, you only need to import the KMSClient and
the commands you need, for example ListAliasesCommand:
// ES5 example
const { KMSClient, ListAliasesCommand } = require("@aws-sdk/client-kms");
// ES6+ example
import { KMSClient, ListAliasesCommand } from "@aws-sdk/client-kms";
To send a request:
send operation on the client, providing the command object as input.const client = new KMSClient({ region: "REGION" });
const params = { /** input parameters */ };
const command = new ListAliasesCommand(params);
We recommend using the await operator to wait for the promise returned by send operation as follows:
// async/await.
try {
const data = await client.send(command);
// process data.
} catch (error) {
// error handling.
} finally {
// finally.
}
You can also use Promise chaining.
client
.send(command)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
})
.finally(() => {
// finally.
});
The aggregated client class is exported from the same package, but without the "Client" suffix.
KMS extends KMSClient and additionally supports all operations, waiters, and paginators as methods.
This style may be familiar to you from the AWS SDK for JavaScript v2.
If you are bundling the AWS SDK, we recommend using only the bare-bones client (KMSClient).
More details are in the blog post on
modular packages in AWS SDK for JavaScript.
import { KMS } from "@aws-sdk/client-kms";
const client = new KMS({ region: "REGION" });
// async/await.
try {
const data = await client.listAliases(params);
// process data.
} catch (error) {
// error handling.
}
// Promises.
client
.listAliases(params)
.then((data) => {
// process data.
})
.catch((error) => {
// error handling.
});
// callbacks (not recommended).
client.listAliases(params, (err, data) => {
// process err and data.
});
When the service returns an exception, the error will include the exception information, as well as response metadata (e.g. request id).
try {
const data = await client.send(command);
// process data.
} catch (error) {
const { requestId, cfId, extendedRequestId } = error.$metadata;
console.log({ requestId, cfId, extendedRequestId });
/**
* The keys within exceptions are also parsed.
* You can access them by specifying exception names:
* if (error.name === 'SomeServiceException') {
* const value = error.specialKeyInException;
* }
*/
}
See also docs/ERROR_HANDLING.
Please use these community resources for getting help. We use GitHub issues for tracking bugs and feature requests, but have limited bandwidth to address them.
aws-sdk-js
on AWS Developer Blog.aws-sdk-js.To test your universal JavaScript code in Node.js, browser and react-native environments, visit our code samples repo.
This client code is generated automatically. Any modifications will be overwritten the next time the @aws-sdk/client-kms package is updated.
To contribute to client you can check our generate clients scripts.
This SDK is distributed under the Apache License, Version 2.0, see LICENSE for more information.
Command API Reference / Input / Output
</details> <details> <summary> ConnectCustomKeyStore </summary>Command API Reference / Input / Output
</details> <details> <summary> CreateAlias </summary>Command API Reference / Input / Output
</details> <details> <summary> CreateCustomKeyStore </summary>Command API Reference / Input / Output
</details> <details> <summary> CreateGrant </summary>Command API Reference / Input / Output
</details> <details> <summary> CreateKey </summary>Command API Reference / Input / Output
</details> <details> <summary> Decrypt </summary>Command API Reference / Input / Output
</details> <details> <summary> DeleteAlias </summary>Command API Reference / Input / Output
</details> <details> <summary> DeleteCustomKeyStore </summary>Command API Reference / Input / Output
</details> <details> <summary> DeleteImportedKeyMaterial </summary>Command API Reference / Input / Output
</details> <details> <summary> DeriveSharedSecret </summary>Command API Reference / Input / Output
</details> <details> <summary> DescribeCustomKeyStores </summary>Command API Reference / Input / Output
</details> <details> <summary> DescribeKey </summary>Command API Reference / Input / Output
</details> <details> <summary> DisableKey </summary>Command API Reference / Input / Output
</details> <details> <summary> DisableKeyRotation </summary>Command API Reference / Input / Output
</details> <details> <summary> DisconnectCustomKeyStore </summary>Command API Reference / Input / Output
</details> <details> <summary> EnableKey </summary>Command API Reference / Input / Output
</details> <details> <summary> EnableKeyRotation </summary>Command API Reference / Input / Output
</details> <details> <summary> Encrypt </summary>Command API Reference / Input / Output
</details> <details> <summary> GenerateDataKey </summary>Command API Reference / Input / Output
</details> <details> <summary> GenerateDataKeyPair </summary>Command API Reference / Input / Output
</details> <details> <summary> GenerateDataKeyPairWithoutPlaintext </summary>Command API Reference / Input / Output
</details> <details> <summary> GenerateDataKeyWithoutPlaintext </summary>Command API Reference / Input / Output
</details> <details> <summary> GenerateMac </summary>Command API Reference / Input / Output
</details> <details> <summary> GenerateRandom </summary>Command API Reference / Input / Output
</details> <details> <summary> GetKeyLastUsage </summary>Command API Reference / Input / Output
</details> <details> <summary> GetKeyPolicy </summary>Command API Reference / Input / Output
</details> <details> <summary> GetKeyRotationStatus </summary>Command API Reference / Input / Output
</details> <details> <summary> GetParametersForImport </summary>Command API Reference / Input / Output
</details> <details> <summary> GetPublicKey </summary>Command API Reference / Input / Output
</details> <details> <summary> ImportKeyMaterial </summary>Command API Reference / Input / Output
</details> <details> <summary> ListAliases </summary>Command API Reference / Input / Output
</details> <details> <summary> ListGrants </summary>Command API Reference / Input / Output
</details> <details> <summary> ListKeyPolicies </summary>Command API Reference / Input / Output
</details> <details> <summary> ListKeyRotations </summary>Command API Reference / Input / Output
</details> <details> <summary> ListKeys </summary>Command API Reference / Input / Output
</details> <details> <summary> ListResourceTags </summary>Command API Reference / Input / Output
</details> <details> <summary> ListRetirableGrants </summary>Command API Reference / Input / Output
</details> <details> <summary> PutKeyPolicy </summary>Command API Reference / Input / Output
</details> <details> <summary> ReEncrypt </summary>Command API Reference / Input / Output
</details> <details> <summary> ReplicateKey </summary>Command API Reference / Input / Output
</details> <details> <summary> RetireGrant </summary>Command API Reference / Input / Output
</details> <details> <summary> RevokeGrant </summary>Command API Reference / Input / Output
</details> <details> <summary> RotateKeyOnDemand </summary>Command API Reference / Input / Output
</details> <details> <summary> ScheduleKeyDeletion </summary>Command API Reference / Input / Output
</details> <details> <summary> Sign </summary>Command API Reference / Input / Output
</details> <details> <summary> TagResource </summary>Command API Reference / Input / Output
</details> <details> <summary> UntagResource </summary>Command API Reference / Input / Output
</details> <details> <summary> UpdateAlias </summary>Command API Reference / Input / Output
</details> <details> <summary> UpdateCustomKeyStore </summary>Command API Reference / Input / Output
</details> <details> <summary> UpdateKeyDescription </summary>Command API Reference / Input / Output
</details> <details> <summary> UpdatePrimaryRegion </summary>Command API Reference / Input / Output
</details> <details> <summary> Verify </summary> </details> <details> <summary> VerifyMac </summary> </details>