create-key AWS CLI 2.15.34 Command Reference
Description
Creates a unique customer managed KMS key in your Amazon Web Services account and Region. You can use a KMS key in cryptographic operations, such as encryption and signing. Some Amazon Web Services services let you use KMS keys that you create and manage to protect your service resources.
A KMS key is a logical representation of a cryptographic key. In addition to the key material used in cryptographic operations, a KMS key includes metadata, such as the key ID, key policy, creation date, description, and key state. For details, see Managing keys in the Key Management Service Developer Guide
Use the parameters of CreateKey
to specify the type of KMS key, the source of its key material, its key policy, description, tags, and other properties.
Note
KMS has replaced the term customer master key (CMK) with KMS key and KMS key . The concept has not changed. To prevent breaking changes, KMS is keeping some variations of this term.To create different types of KMS keys, use the following guidance:
Symmetric encryption KMS key
By default, CreateKey
creates a symmetric encryption KMS key with key material that KMS generates. This is the basic and most widely used type of KMS key, and provides the best performance.
To create a symmetric encryption KMS key, you don’t need to specify any parameters. The default value for KeySpec
, SYMMETRIC_DEFAULT
, the default value for KeyUsage
, ENCRYPT_DECRYPT
, and the default value for Origin
, AWS_KMS
, create a symmetric encryption KMS key with KMS key material.
If you need a key for basic encryption and decryption or you are creating a KMS key to protect your resources in an Amazon Web Services service, create a symmetric encryption KMS key. The key material in a symmetric encryption key never leaves KMS unencrypted. You can use a symmetric encryption KMS key to encrypt and decrypt data up to 4,096 bytes, but they are typically used to generate data keys and data keys pairs. For details, see GenerateDataKey and GenerateDataKeyPair .
Asymmetric KMS keys
To create an asymmetric KMS key, use the KeySpec
parameter to specify the type of key material in the KMS key. Then, use the KeyUsage
parameter to determine whether the KMS key will be used to encrypt and decrypt or sign and verify. You can’t change these properties after the KMS key is created.
Asymmetric KMS keys contain an RSA key pair, Elliptic Curve (ECC) key pair, or an SM2 key pair (China Regions only). The private key in an asymmetric KMS key never leaves KMS unencrypted. However, you can use the GetPublicKey operation to download the public key so it can be used outside of KMS. KMS keys with RSA or SM2 key pairs can be used to encrypt or decrypt data or sign and verify messages (but not both). KMS keys with ECC key pairs can be used only to sign and verify messages. For information about asymmetric KMS keys, see Asymmetric KMS keys in the Key Management Service Developer Guide .
HMAC KMS key
To create an HMAC KMS key, set the KeySpec
parameter to a key spec value for HMAC KMS keys. Then set the KeyUsage
parameter to GENERATE_VERIFY_MAC
. You must set the key usage even though GENERATE_VERIFY_MAC
is the only valid key usage value for HMAC KMS keys. You can’t change these properties after the KMS key is created.
HMAC KMS keys are symmetric keys that never leave KMS unencrypted. You can use HMAC keys to generate ( GenerateMac ) and verify ( VerifyMac ) HMAC codes for messages up to 4096 bytes.
Multi-Region primary keys Imported key material
To create a multi-Region primary key in the local Amazon Web Services Region, use the MultiRegion
parameter with a value of True
. To create a multi-Region replica key , that is, a KMS key with the same key ID and key material as a primary key, but in a different Amazon Web Services Region, use the ReplicateKey operation. To change a replica key to a primary key, and its primary key to a replica key, use the UpdatePrimaryRegion operation.
You can create multi-Region KMS keys for all supported KMS key types: symmetric encryption KMS keys, HMAC KMS keys, asymmetric encryption KMS keys, and asymmetric signing KMS keys. You can also create multi-Region keys with imported key material. However, you can’t create multi-Region keys in a custom key store.
This operation supports multi-Region keys , an KMS feature that lets you create multiple interoperable KMS keys in different Amazon Web Services Regions. Because these KMS keys have the same key ID, key material, and other metadata, you can use them interchangeably to encrypt data in one Amazon Web Services Region and decrypt it in a different Amazon Web Services Region without re-encrypting the data or making a cross-Region call. For more information about multi-Region keys, see Multi-Region keys in KMS in the Key Management Service Developer Guide .
To import your own key material into a KMS key, begin by creating a KMS key with no key material. To do this, use the Origin
parameter of CreateKey
with a value of EXTERNAL
. Next, use GetParametersForImport operation to get a public key and import token. Use the wrapping public key to encrypt your key material. Then, use ImportKeyMaterial with your import token to import the key material. For step-by-step instructions, see Importing Key Material in the * Key Management Service Developer Guide * .
You can import key material into KMS keys of all supported KMS key types: symmetric encryption KMS keys, HMAC KMS keys, asymmetric encryption KMS keys, and asymmetric signing KMS keys. You can also create multi-Region keys with imported key material. However, you can’t import key material into a KMS key in a custom key store.
To create a multi-Region primary key with imported key material, use the Origin
parameter of CreateKey
with a value of EXTERNAL
and the MultiRegion
parameter with a value of True
. To create replicas of the multi-Region primary key, use the ReplicateKey operation. For instructions, see `Importing key material into multi-Region keys <https://docs.aws.amazon.com/kms/latest/developerguide/multi-region-keys-import.html >`__ . For more information about multi-Region keys, see Multi-Region keys in KMS in the Key Management Service Developer Guide .
Custom key store
A custom key store lets you protect your Amazon Web Services resources using keys in a backing key store that you own and manage. When you request a cryptographic operation with a KMS key in a custom key store, the operation is performed in the backing key store using its cryptographic keys.
KMS supports CloudHSM key stores backed by an CloudHSM cluster and external key stores backed by an external key manager outside of Amazon Web Services. When you create a KMS key in an CloudHSM key store, KMS generates an encryption key in the CloudHSM cluster and associates it with the KMS key. When you create a KMS key in an external key store, you specify an existing encryption key in the external key manager.
Note
Some external key managers provide a simpler method for creating a KMS key in an external key store. For details, see your external key manager documentation.Before you create a KMS key in a custom key store, the ConnectionState
of the key store must be CONNECTED
. To connect the custom key store, use the ConnectCustomKeyStore operation. To find the ConnectionState
, use the DescribeCustomKeyStores operation.
To create a KMS key in a custom key store, use the CustomKeyStoreId
. Use the default KeySpec
value, SYMMETRIC_DEFAULT
, and the default KeyUsage
value, ENCRYPT_DECRYPT
to create a symmetric encryption key. No other key type is supported in a custom key store.
To create a KMS key in an CloudHSM key store , use the Origin
parameter with a value of AWS_CLOUDHSM
. The CloudHSM cluster that is associated with the custom key store must have at least two active HSMs in different Availability Zones in the Amazon Web Services Region.
To create a KMS key in an external key store , use the Origin
parameter with a value of EXTERNAL_KEY_STORE
and an XksKeyId
parameter that identifies an existing external key.
Note
Some external key managers provide a simpler method for creating a KMS key in an external key store. For details, see your external key manager documentation.
Cross-account use : No. You cannot use this operation to create a KMS key in a different Amazon Web Services account.
Required permissions : kms:CreateKey (IAM policy). To use the Tags
parameter, kms:TagResource (IAM policy). For examples and information about related permissions, see Allow a user to create KMS keys in the Key Management Service Developer Guide .
Related operations:
- DescribeKey
- ListKeys
- ScheduleKeyDeletion
See also: AWS API Documentation
Global Options
--debug
(boolean)
Turn on debug logging.
--endpoint-url
(string)
Override command’s default URL with the given URL.
--no-verify-ssl
(boolean)
By default, the AWS CLI uses SSL when communicating with AWS services. For each SSL connection, the AWS CLI will verify SSL certificates. This option overrides the default behavior of verifying SSL certificates.
--no-paginate
(boolean)
Disable automatic pagination.
--output
(string)
The formatting style for command output.
- json
- text
- table
- yaml
- yaml-stream
--query
(string)
A JMESPath query to use in filtering the response data.
--profile
(string)
Use a specific profile from your credential file.
--region
(string)
The region to use. Overrides config/env settings.
--version
(string)
Display the version of this tool.
--color
(string)
Turn on/off color output.
- on
- off
- auto
--no-sign-request
(boolean)
Do not sign requests. Credentials will not be loaded if this argument is provided.
--ca-bundle
(string)
The CA certificate bundle to use when verifying SSL certificates. Overrides config/env settings.
--cli-read-timeout
(int)
The maximum socket read time in seconds. If the value is set to 0, the socket read will be blocking and not timeout. The default value is 60 seconds.
--cli-connect-timeout
(int)
The maximum socket connect time in seconds. If the value is set to 0, the socket connect will be blocking and not timeout. The default value is 60 seconds.
--cli-binary-format
(string)
The formatting style to be used for binary blobs. The default format is base64. The base64 format expects binary blobs to be provided as a base64 encoded string. The raw-in-base64-out format preserves compatibility with AWS CLI V1 behavior and binary values must be passed literally. When providing contents from a file that map to a binary blob fileb://
will always be treated as binary and use the file contents directly regardless of the cli-binary-format
setting. When using file://
the file contents will need to properly formatted for the configured cli-binary-format
.
- base64
- raw-in-base64-out
--no-cli-pager
(boolean)
Disable cli pager for output.
--cli-auto-prompt
(boolean)
Automatically prompt for CLI input parameters.
--no-cli-auto-prompt
(boolean)
Disable automatically prompt for CLI input parameters.
Examples
Note
To use the following examples, you must have the AWS CLI installed and configured. See the Getting started guide in the AWS CLI User Guide for more information.
Unless otherwise stated, all examples have unix-like quotation rules. These examples will need to be adapted to your terminal’s quoting rules. See Using quotation marks with strings in the AWS CLI User Guide .
Example 1: To create a customer managed KMS key in AWS KMS
The following create-key
example creates a symmetric encryption KMS key.
To create the basic KMS key, a symmetric encryption key, you do not need to specify any parameters. The default values for those parameters create a symmetric encryption key.
Because this command doesn’t specify a key policy, the KMS key gets the default key policy for programmatically created KMS keys. To view the key policy, use the get-key-policy
command. To change the key policy, use the put-key-policy
command.
aws kms create-key
The create-key
command returns the key metadata, including the key ID and ARN of the new KMS key. You can use these values to identify the KMS key in other AWS KMS operations. The output does not include the tags. To view the tags for a KMS key, use the list-resource-tags command
.
Output:
{ "KeyMetadata": { "AWSAccountId": "111122223333", "Arn": "arn:aws:kms:us-west-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "CreationDate": "2017-07-05T14:04:55-07:00", "CustomerMasterKeySpec": "SYMMETRIC_DEFAULT", "Description": "", "Enabled": true, "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "KeyManager": "CUSTOMER", "KeySpec": "SYMMETRIC_DEFAULT", "KeyState": "Enabled", "KeyUsage": "ENCRYPT_DECRYPT", "MultiRegion": false, "Origin": "AWS_KMS" "EncryptionAlgorithms": [ "SYMMETRIC_DEFAULT" ] } }
Note: The create-key
command does not let you specify an alias, To create an alias for the new KMS key, use the create-alias
command.
For more information, see Creating keys in the AWS Key Management Service Developer Guide.
Example 2: To create an asymmetric RSA KMS key for encryption and decryption
The following create-key
example creates a KMS key that contains an asymmetric RSA key pair for encryption and decryption.
aws kms create-key \ --key-spec RSA_4096 \ --key-usage ENCRYPT_DECRYPT
Output:
{ "KeyMetadata": { "Arn": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "AWSAccountId": "111122223333", "CreationDate": "2021-04-05T14:04:55-07:00", "CustomerMasterKeySpec": "RSA_4096", "Description": "", "Enabled": true, "EncryptionAlgorithms": [ "RSAES_OAEP_SHA_1", "RSAES_OAEP_SHA_256" ], "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "KeyManager": "CUSTOMER", "KeySpec": "RSA_4096", "KeyState": "Enabled", "KeyUsage": "ENCRYPT_DECRYPT", "MultiRegion": false, "Origin": "AWS_KMS" } }
For more information, see Asymmetric keys in AWS KMS in the AWS Key Management Service Developer Guide.
Example 3: To create an asymmetric elliptic curve KMS key for signing and verification
To create an asymmetric KMS key that contains an asymmetric elliptic curve (ECC) key pair for signing and verification. The --key-usage
parameter is required even though SIGN_VERIFY
is the only valid value for ECC KMS keys.
aws kms create-key \ --key-spec ECC_NIST_P521 \ --key-usage SIGN_VERIFY
Output:
{ "KeyMetadata": { "Arn": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "AWSAccountId": "111122223333", "CreationDate": "2019-12-02T07:48:55-07:00", "CustomerMasterKeySpec": "ECC_NIST_P521", "Description": "", "Enabled": true, "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "KeyManager": "CUSTOMER", "KeySpec": "ECC_NIST_P521", "KeyState": "Enabled", "KeyUsage": "SIGN_VERIFY", "MultiRegion": false, "Origin": "AWS_KMS", "SigningAlgorithms": [ "ECDSA_SHA_512" ] } }
For more information, see Asymmetric keys in AWS KMS in the AWS Key Management Service Developer Guide.
Example 4: To create an HMAC KMS key
The following create-key
example creates a 384-bit HMAC KMS key. The GENERATE_VERIFY_MAC
value for the --key-usage
parameter is required even though it’s the only valid value for HMAC KMS keys.
aws kms create-key \ --key-spec HMAC_384 \ --key-usage GENERATE_VERIFY_MAC
Output:
{ "KeyMetadata": { "Arn": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "AWSAccountId": "111122223333", "CreationDate": "2022-04-05T14:04:55-07:00", "CustomerMasterKeySpec": "HMAC_384", "Description": "", "Enabled": true, "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "KeyManager": "CUSTOMER", "KeySpec": "HMAC_384", "KeyState": "Enabled", "KeyUsage": "GENERATE_VERIFY_MAC", "MacAlgorithms": [ "HMAC_SHA_384" ], "MultiRegion": false, "Origin": "AWS_KMS" } }
For more information, see HMAC keys in AWS KMS in the AWS Key Management Service Developer Guide.
Example 4: To create a multi-Region primary KMS key
The following create-key
example creates a multi-Region primary symmetric encryption key. Because the default values for all parameters create a symmetric encryption key, only the --multi-region
parameter is required for this KMS key. In the AWS CLI, to indicate that a Boolean parameter is true, just specify the parameter name.
aws kms create-key \ --multi-region
Output:
{ "KeyMetadata": { "Arn": "arn:aws:kms:us-west-2:111122223333:key/mrk-1234abcd12ab34cd56ef12345678990ab", "AWSAccountId": "111122223333", "CreationDate": "2021-09-02T016:15:21-09:00", "CustomerMasterKeySpec": "SYMMETRIC_DEFAULT", "Description": "", "Enabled": true, "EncryptionAlgorithms": [ "SYMMETRIC_DEFAULT" ], "KeyId": "mrk-1234abcd12ab34cd56ef12345678990ab", "KeyManager": "CUSTOMER", "KeySpec": "SYMMETRIC_DEFAULT", "KeyState": "Enabled", "KeyUsage": "ENCRYPT_DECRYPT", "MultiRegion": true, "MultiRegionConfiguration": { "MultiRegionKeyType": "PRIMARY", "PrimaryKey": { "Arn": "arn:aws:kms:us-west-2:111122223333:key/mrk-1234abcd12ab34cd56ef12345678990ab", "Region": "us-west-2" }, "ReplicaKeys": [] }, "Origin": "AWS_KMS" } }
For more information, see Asymmetric keys in AWS KMS in the AWS Key Management Service Developer Guide.
Example 5: To create a KMS key for imported key material
The following create-key
example creates a creates a KMS key with no key material. When the operation is complete, you can import your own key material into the KMS key. To create this KMS key, set the --origin
parameter to EXTERNAL
.
aws kms create-key \ --origin EXTERNAL
Output:
{ "KeyMetadata": { "Arn": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "AWSAccountId": "111122223333", "CreationDate": "2019-12-02T07:48:55-07:00", "CustomerMasterKeySpec": "SYMMETRIC_DEFAULT", "Description": "", "Enabled": false, "EncryptionAlgorithms": [ "SYMMETRIC_DEFAULT" ], "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "KeyManager": "CUSTOMER", "KeySpec": "SYMMETRIC_DEFAULT", "KeyState": "PendingImport", "KeyUsage": "ENCRYPT_DECRYPT", "MultiRegion": false, "Origin": "EXTERNAL" } }
For more information, see Importing key material in AWS KMS keys in the AWS Key Management Service Developer Guide.
Example 6: To create a KMS key in an AWS CloudHSM key store
The following create-key
example creates a creates a KMS key in the specified AWS CloudHSM key store. The operation creates the KMS key and its metadata in AWS KMS and creates the key material in the AWS CloudHSM cluster associated with the custom key store. The --custom-key-store-id
and --origin
parameters are required.
aws kms create-key \ --origin AWS_CLOUDHSM \ --custom-key-store-id cks-1234567890abcdef0
Output:
{ "KeyMetadata": { "Arn": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "AWSAccountId": "111122223333", "CloudHsmClusterId": "cluster-1a23b4cdefg", "CreationDate": "2019-12-02T07:48:55-07:00", "CustomerMasterKeySpec": "SYMMETRIC_DEFAULT", "CustomKeyStoreId": "cks-1234567890abcdef0", "Description": "", "Enabled": true, "EncryptionAlgorithms": [ "SYMMETRIC_DEFAULT" ], "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "KeyManager": "CUSTOMER", "KeySpec": "SYMMETRIC_DEFAULT", "KeyState": "Enabled", "KeyUsage": "ENCRYPT_DECRYPT", "MultiRegion": false, "Origin": "AWS_CLOUDHSM" } }
For more information, see AWS CloudHSM key stores in the AWS Key Management Service Developer Guide.
Example 7: To create a KMS key in an external key store
The following create-key
example creates a creates a KMS key in the specified external key store. The --custom-key-store-id
, --origin
, and --xks-key-id
parameters are required in this command.
The
--xks-key-id
parameter specifies the ID of an existing symmetric encryption key in your external key manager. This key serves as the external key material for the KMS key.The value of the
--origin
parameter must beEXTERNAL_KEY_STORE
.The
custom-key-store-id
parameter must identify an external key store that is connected to its external key store proxy.aws kms create-key \ --origin EXTERNAL_KEY_STORE \ --custom-key-store-id cks-9876543210fedcba9 \ --xks-key-id bb8562717f809024
Output:
{ "KeyMetadata": { "Arn": "arn:aws:kms:us-east-2:111122223333:key/1234abcd-12ab-34cd-56ef-1234567890ab", "AWSAccountId": "111122223333", "CreationDate": "2022-12-02T07:48:55-07:00", "CustomerMasterKeySpec": "SYMMETRIC_DEFAULT", "CustomKeyStoreId": "cks-9876543210fedcba9", "Description": "", "Enabled": true, "EncryptionAlgorithms": [ "SYMMETRIC_DEFAULT" ], "KeyId": "1234abcd-12ab-34cd-56ef-1234567890ab", "KeyManager": "CUSTOMER", "KeySpec": "SYMMETRIC_DEFAULT", "KeyState": "Enabled", "KeyUsage": "ENCRYPT_DECRYPT", "MultiRegion": false, "Origin": "EXTERNAL_KEY_STORE", "XksKeyConfiguration": { "Id": "bb8562717f809024" } } }
For more information, see External key stores in the AWS Key Management Service Developer Guide.
ncG1vNJzZmiZp6iwrbWNmqSasp%2Bjrri%2FjZympmemZ3ylu8KupJ6mpJbBqrvNaJipoV%2BhrrWx0q1mq52Wmr%2BmusKeZqSlo2Sws7HArZxmo5Wue6nAzKU%3D