KMS¶
Installation¶
To install the KMS client:
Client¶
AsyncKMSClient
¶
Bases: AsyncClient[AsyncKMSConfig]
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 Key Management Service Developer Guide .
Note
KMS has replaced the term customer master key (CMK) with Key Management Service key and KMS key. The concept has not changed. To prevent breaking changes, KMS is keeping some variations of this term.
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 Tools for Amazon Web Services.
We recommend that you use the Amazon Web Services SDKs to make programmatic API calls to KMS.
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 Service endpoints in the Key Management Service topic of the Amazon Web Services General Reference and Dual-stack endpoint support in the KMS Developer Guide.
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.
Note
With current technology, brute force attacks on KMS TLS cipher suite key exchange mechanisms are not feasible. However, cipher suites that use Rivest--Shamir--Adleman (RSA) or Diffie-Hellman (DH) key exchange will be susceptible if large-scale quantum computing becomes practical. NIST IR 8547 on the NIST website establishes a timeline to phase out quantum-vulnerable algorithms by 2030 and disallow them entirely by 2035. If your applications rely on the long-term confidentiality of KMS API traffic, we recommend that you use post-quantum TLS with KMS. For more information about post-quantum cybersecurity, see Post-Quantum Cybersecurity Resources on the National Security Agency (NSA) website.
Signing Requests
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.
All KMS requests must be signed with Signature Version 4.
Logging API Requests
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 CloudTrail User Guide.
Additional Resources
For more information about credentials and request signing, see the following:
-
Amazon Web Services Security Credentials - This topic provides general information about the types of credentials used to access Amazon Web Services.
-
Temporary Security Credentials - This section of the IAM User Guide describes how to create and use temporary security credentials.
-
Signature Version 4 Signing Process - This set of topics walks you through the process of signing a request using an access key ID and a secret access key.
Commonly Used API Operations
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.
-
Encrypt
-
Decrypt
-
GenerateDataKey
-
GenerateDataKeyWithoutPlaintext
Operations¶
cancel_key_deletionconnect_custom_key_storecreate_aliascreate_custom_key_storecreate_grantcreate_keydecapsulatedecryptdelete_aliasdelete_custom_key_storedelete_imported_key_materialderive_shared_secretdescribe_custom_key_storesdescribe_keydisable_keydisable_key_rotationdisconnect_custom_key_storeenable_keyenable_key_rotationencapsulateencryptgenerate_data_keygenerate_data_key_pairgenerate_data_key_pair_without_plaintextgenerate_data_key_without_plaintextgenerate_macgenerate_randomget_key_last_usageget_key_policyget_key_rotation_statusget_parameters_for_importget_public_keyimport_key_materiallist_aliaseslist_grantslist_key_policieslist_key_rotationslist_keyslist_resource_tagslist_retirable_grantsput_key_policyre_encryptreplicate_keyretire_grantrevoke_grantrotate_key_on_demandschedule_key_deletionsigntag_resourceuntag_resourceupdate_aliasupdate_custom_key_storeupdate_key_descriptionupdate_primary_regionverifyverify_mac
Configuration¶
AsyncKMSConfig
dataclass
¶
Bases: AsyncAwsConfig
KMS configuration (async-resolved).
Attributes¶
auth_scheme_resolver
class-attribute
instance-attribute
¶
An auth scheme resolver that determines the auth scheme for each operation.
auth_schemes
class-attribute
instance-attribute
¶
A map of auth scheme ids to auth schemes.
aws_access_key_id
class-attribute
instance-attribute
¶
aws_access_key_id: str | None = None
The identifier for a secret access key.
aws_credentials_identity_resolver
class-attribute
instance-attribute
¶
aws_credentials_identity_resolver: AsyncIdentityResolver[AWSCredentialsIdentity, AWSIdentityProperties] | None = None
Resolves AWS Credentials. Required for operations that use Sigv4 Auth.
aws_secret_access_key
class-attribute
instance-attribute
¶
aws_secret_access_key: str | None = None
A secret access key that can be used to sign requests.
aws_session_token
class-attribute
instance-attribute
¶
aws_session_token: str | None = None
The session token used with temporary AWS credentials.
endpoint_resolver
class-attribute
instance-attribute
¶
The endpoint resolver used to resolve the final endpoint per-operation based on the configuration.
interceptors
class-attribute
instance-attribute
¶
The list of interceptors, which are hooks that are called during the execution of a request.
protocol
class-attribute
instance-attribute
¶
Pass a protocol class reference from smithy_aws_core.aio.protocols to select the protocol, e.g. protocol=AsyncAwsJson10ClientProtocol. For custom protocols a protocol instance may also be passed.
region
class-attribute
instance-attribute
¶
region: str | None = None
The AWS region to connect to. The configured region is used to determine the service endpoint.
sdk_ua_app_id
class-attribute
instance-attribute
¶
sdk_ua_app_id: str | None = None
A unique and opaque application ID that is appended to the User-Agent header.
use_dualstack_endpoint
class-attribute
instance-attribute
¶
use_dualstack_endpoint: bool | None = None
When true, use the dual-stack endpoint. If the configured endpoint does not support dual-stack, dispatching the request MAY return an error.
use_fips_endpoint
class-attribute
instance-attribute
¶
use_fips_endpoint: bool | None = None
When true, send this request to the FIPS-compliant regional endpoint. If the configured endpoint does not have a FIPS compliant endpoint, dispatching the request will return an error.
user_agent_extra
class-attribute
instance-attribute
¶
user_agent_extra: str | None = None
Additional suffix to be added to the User-Agent header.
Methods:¶
resolve
async
classmethod
¶
resolve(*, profile: str | None = None, fs: AsyncFileSystem | None = None, config_file_path: str | None = None, credentials_file_path: str | None = None, **overrides: Unpack[_AsyncKMSConfigOverrides]) -> Self
Resolve config from environment, config files, defaults, and explicit overrides.
Plugin
module-attribute
¶
Plugin: TypeAlias = Callable[[AsyncKMSConfig], None]
A callable that customizes a client configuration. Service-level plugins are applied once to the base configuration inherited by every operation. Operation-level plugins apply only to a single operation invocation.
Structures¶
AliasListEntryCustomKeyStoresListEntryGrantConstraintsGrantListEntryKeyLastUsageDataKeyListEntryKeyMetadataMultiRegionConfigurationMultiRegionKeyRecipientInfoRotationsListEntryTagXksKeyConfigurationTypeXksProxyAuthenticationCredentialTypeXksProxyConfigurationType
Errors¶
AlreadyExistsExceptionCloudHsmClusterInUseExceptionCloudHsmClusterInvalidConfigurationExceptionCloudHsmClusterNotActiveExceptionCloudHsmClusterNotFoundExceptionCloudHsmClusterNotRelatedExceptionConflictExceptionCustomKeyStoreHasCMKsExceptionCustomKeyStoreInvalidStateExceptionCustomKeyStoreNameInUseExceptionCustomKeyStoreNotFoundExceptionDependencyTimeoutExceptionDisabledExceptionDryRunOperationExceptionExpiredImportTokenExceptionIncorrectKeyExceptionIncorrectKeyMaterialExceptionIncorrectTrustAnchorExceptionInvalidAliasNameExceptionInvalidArnExceptionInvalidCiphertextExceptionInvalidGrantIdExceptionInvalidGrantTokenExceptionInvalidImportTokenExceptionInvalidKeyUsageExceptionInvalidMarkerExceptionKMSInternalExceptionKMSInvalidMacExceptionKMSInvalidSignatureExceptionKMSInvalidStateExceptionKeyUnavailableExceptionLimitExceededExceptionMalformedPolicyDocumentExceptionNotFoundExceptionServiceErrorTagExceptionUnsupportedOperationExceptionXksKeyAlreadyInUseExceptionXksKeyInvalidConfigurationExceptionXksKeyNotFoundExceptionXksProxyIncorrectAuthenticationCredentialExceptionXksProxyInvalidConfigurationExceptionXksProxyInvalidResponseExceptionXksProxyUriEndpointInUseExceptionXksProxyUriInUseExceptionXksProxyUriUnreachableExceptionXksProxyVpcEndpointServiceInUseExceptionXksProxyVpcEndpointServiceInvalidConfigurationExceptionXksProxyVpcEndpointServiceNotFoundException
Enums¶
AlgorithmSpecConnectionErrorCodeTypeConnectionStateTypeCustomKeyStoreTypeCustomerMasterKeySpecDataKeyPairSpecDataKeySpecDryRunModifierTypeEncapsulationAlgorithmSpecEncryptionAlgorithmSpecExpirationModelTypeGrantOperationImportStateImportTypeIncludeKeyMaterialKeyAgreementAlgorithmSpecKeyEncryptionMechanismKeyLastUsageTrackingOperationKeyManagerTypeKeyMaterialStateKeySpecKeyStateKeyUsageTypeMacAlgorithmSpecMessageTypeMultiRegionKeyTypeOriginTypeRotationTypeSigningAlgorithmSpecWrappingKeySpecXksProxyConnectivityType