AWS Key Management Service

2015/05/07 - AWS Key Management Service - 25 new api methods

Encrypt (new) Link ¶

Encrypts plaintext into ciphertext by using a customer master key. The Encrypt function has two primary use cases:

  • You can encrypt up to 4 KB of arbitrary data such as an RSA key, a database password, or other sensitive customer information.

  • If you are moving encrypted data from one region to another, you can use this API to encrypt in the new region the plaintext data key that was used to encrypt the data in the original region. This provides you with an encrypted copy of the data key that can be decrypted in the new region and used there to decrypt the encrypted data.

Unless you are moving encrypted data from one region to another, you don't use this function to encrypt a generated data key within a region. You retrieve data keys already encrypted by calling the GenerateDataKey or GenerateDataKeyWithoutPlaintext function. Data keys don't need to be encrypted again by calling Encrypt .

If you want to encrypt data locally in your application, you can use the GenerateDataKey function to return a plaintext data encryption key and a copy of the key encrypted under the customer master key (CMK) of your choosing.

Request Syntax

client.encrypt(
    KeyId='string',
    Plaintext=b'bytes',
    EncryptionContext={
        'string': 'string'
    },
    GrantTokens=[
        'string',
    ]
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier, a fully specified ARN to either an alias or a key, or an alias name prefixed by "alias/".

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Alias ARN Example - arn:aws:kms:us-east-1:123456789012:/alias/MyAliasName

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

  • Alias Name Example - alias/MyAliasName

type Plaintext

bytes

param Plaintext

[REQUIRED]

Data to be encrypted.

type EncryptionContext

dict

param EncryptionContext

Name/value pair that specifies the encryption context to be used for authenticated encryption. If used here, the same value must be supplied to the Decrypt API or decryption will fail. For more information, see Encryption Context.

  • (string) --

    • (string) --

type GrantTokens

list

param GrantTokens

For more information, see Grant Tokens.

  • (string) --

rtype

dict

returns

Response Syntax

{
    'CiphertextBlob': b'bytes',
    'KeyId': 'string'
}

Response Structure

  • (dict) --

    • CiphertextBlob (bytes) --

      The encrypted plaintext. If you are using the CLI, the value is Base64 encoded. Otherwise, it is not encoded.

    • KeyId (string) --

      The ID of the key used during encryption.

CreateKey (new) Link ¶

Creates a customer master key. Customer master keys can be used to encrypt small amounts of data (less than 4K) directly, but they are most commonly used to encrypt or envelope data keys that are then used to encrypt customer data. For more information about data keys, see GenerateDataKey and GenerateDataKeyWithoutPlaintext.

Request Syntax

client.create_key(
    Policy='string',
    Description='string',
    KeyUsage='ENCRYPT_DECRYPT'
)
type Policy

string

param Policy

Policy to be attached to the key. This is required and delegates back to the account. The key is the root of trust.

type Description

string

param Description

Description of the key. We recommend that you choose a description that helps your customer decide whether the key is appropriate for a task.

type KeyUsage

string

param KeyUsage

Specifies the intended use of the key. Currently this defaults to ENCRYPT/DECRYPT, and only symmetric encryption and decryption are supported.

rtype

dict

returns

Response Syntax

{
    'KeyMetadata': {
        'AWSAccountId': 'string',
        'KeyId': 'string',
        'Arn': 'string',
        'CreationDate': datetime(2015, 1, 1),
        'Enabled': True|False,
        'Description': 'string',
        'KeyUsage': 'ENCRYPT_DECRYPT'
    }
}

Response Structure

  • (dict) --

    • KeyMetadata (dict) --

      Metadata associated with the key.

      • AWSAccountId (string) --

        Account ID number.

      • KeyId (string) --

        Unique identifier for the key.

      • Arn (string) --

        Key ARN (Amazon Resource Name).

      • CreationDate (datetime) --

        Date the key was created.

      • Enabled (boolean) --

        Value that specifies whether the key is enabled.

      • Description (string) --

        The description of the key.

      • KeyUsage (string) --

        A value that specifies what operation(s) the key can perform.

EnableKey (new) Link ¶

Marks a key as enabled, thereby permitting its use. You can have up to 25 enabled keys at one time.

Request Syntax

client.enable_key(
    KeyId='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

returns

None

CreateAlias (new) Link ¶

Creates a display name for a customer master key. An alias can be used to identify a key and should be unique. The console enforces a one-to-one mapping between the alias and a key. An alias name can contain only alphanumeric characters, forward slashes (/), underscores (_), and dashes (-). An alias must start with the word "alias" followed by a forward slash (alias/). An alias that begins with "aws" after the forward slash (alias/aws...) is reserved by Amazon Web Services (AWS).

Request Syntax

client.create_alias(
    AliasName='string',
    TargetKeyId='string'
)
type AliasName

string

param AliasName

[REQUIRED]

String that contains the display name. Aliases that begin with AWS are reserved.

type TargetKeyId

string

param TargetKeyId

[REQUIRED]

An identifier of the key for which you are creating the alias. This value cannot be another alias but can be a globally unique identifier or a fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

returns

None

RevokeGrant (new) Link ¶

Revokes a grant. You can revoke a grant to actively deny operations that depend on it.

Request Syntax

client.revoke_grant(
    KeyId='string',
    GrantId='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key associated with the grant. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

type GrantId

string

param GrantId

[REQUIRED]

Identifier of the grant to be revoked.

returns

None

ListAliases (new) Link ¶

Lists all of the key aliases in the account.

Request Syntax

client.list_aliases(
    Limit=123,
    Marker='string'
)
type Limit

integer

param Limit

Specify this parameter when paginating results to indicate the maximum number of aliases you want in each response. If there are additional aliases beyond the maximum you specify, the Truncated response element will be set to true.

type Marker

string

param Marker

Use this parameter when paginating results, and only in a subsequent request after you've received a response where the results are truncated. Set it to the value of the NextMarker element in the response you just received.

rtype

dict

returns

Response Syntax

{
    'Aliases': [
        {
            'AliasName': 'string',
            'AliasArn': 'string',
            'TargetKeyId': 'string'
        },
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) --

    • Aliases (list) --

      A list of key aliases in the user's account.

      • (dict) -- Contains information about an alias.

        • AliasName (string) --

          String that contains the alias.

        • AliasArn (string) --

          String that contains the key ARN.

        • TargetKeyId (string) --

          String that contains the key identifier pointed to by the alias.

    • NextMarker (string) --

      If Truncated is true, this value is present and contains the value to use for the Marker request parameter in a subsequent pagination request.

    • Truncated (boolean) --

      A flag that indicates whether there are more items in the list. If your results were truncated, you can make a subsequent pagination request using the Marker request parameter to retrieve more aliases in the list.

GetKeyPolicy (new) Link ¶

Retrieves a policy attached to the specified key.

Request Syntax

client.get_key_policy(
    KeyId='string',
    PolicyName='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

type PolicyName

string

param PolicyName

[REQUIRED]

String that contains the name of the policy. Currently, this must be "default". Policy names can be discovered by calling ListKeyPolicies.

rtype

dict

returns

Response Syntax

{
    'Policy': 'string'
}

Response Structure

  • (dict) --

    • Policy (string) --

      A policy document in JSON format.

ListGrants (new) Link ¶

List the grants for a specified key.

Request Syntax

client.list_grants(
    KeyId='string',
    Limit=123,
    Marker='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

type Limit

integer

param Limit

Specify this parameter only when paginating results to indicate the maximum number of grants you want listed in the response. If there are additional grants beyond the maximum you specify, the Truncated response element will be set to true.

type Marker

string

param Marker

Use this parameter only when paginating results, and only in a subsequent request after you've received a response where the results are truncated. Set it to the value of the NextMarker in the response you just received.

rtype

dict

returns

Response Syntax

{
    'Grants': [
        {
            'GrantId': 'string',
            'GranteePrincipal': 'string',
            'RetiringPrincipal': 'string',
            'IssuingAccount': 'string',
            'Operations': [
                'Decrypt'|'Encrypt'|'GenerateDataKey'|'GenerateDataKeyWithoutPlaintext'|'ReEncryptFrom'|'ReEncryptTo'|'CreateGrant'|'RetireGrant',
            ],
            'Constraints': {
                'EncryptionContextSubset': {
                    'string': 'string'
                },
                'EncryptionContextEquals': {
                    'string': 'string'
                }
            }
        },
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) --

    • Grants (list) --

      A list of grants.

      • (dict) --

        Contains information about each entry in the grant list.

        • GrantId (string) --

          Unique grant identifier.

        • GranteePrincipal (string) --

          The principal that receives the grant permission.

        • RetiringPrincipal (string) --

          The principal that can retire the account.

        • IssuingAccount (string) --

          The account under which the grant was issued.

        • Operations (list) --

          List of operations permitted by the grant. This can be any combination of one or more of the following values:

          • Decrypt

          • Encrypt

          • GenerateDataKey

          • GenerateDataKeyWithoutPlaintext

          • ReEncryptFrom

          • ReEncryptTo

          • CreateGrant

          • (string) --

        • Constraints (dict) --

          Specifies the conditions under which the actions specified by the Operations parameter are allowed.

          • EncryptionContextSubset (dict) -- The constraint equals the full encryption context.

            • (string) --

              • (string) --

          • EncryptionContextEquals (dict) -- The constraint contains additional key/value pairs that serve to further limit the grant.

            • (string) --

              • (string) --

    • NextMarker (string) --

      If Truncated is true, this value is present and contains the value to use for the Marker request parameter in a subsequent pagination request.

    • Truncated (boolean) --

      A flag that indicates whether there are more items in the list. If your results were truncated, you can make a subsequent pagination request using the Marker request parameter to retrieve more grants in the list.

GetKeyRotationStatus (new) Link ¶

Retrieves a Boolean value that indicates whether key rotation is enabled for the specified key.

Request Syntax

client.get_key_rotation_status(
    KeyId='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

rtype

dict

returns

Response Syntax

{
    'KeyRotationEnabled': True|False
}

Response Structure

  • (dict) --

    • KeyRotationEnabled (boolean) -- A Boolean value that specifies whether key rotation is enabled.

GenerateDataKey (new) Link ¶

Generates a data key that you can use in your application to locally encrypt data. This call returns a plaintext version of the key in the Plaintext field of the response object and an encrypted copy of the key in the CiphertextBlob field. The key is encrypted by using the master key specified by the KeyId field. To decrypt the encrypted key, pass it to the Decrypt API.

We recommend that you use the following pattern to locally encrypt data: call the GenerateDataKey API, use the key returned in the Plaintext response field to locally encrypt data, and then erase the plaintext data key from memory. Store the encrypted data key (contained in the CiphertextBlob field) alongside of the locally encrypted data.

Note

You should not call the Encrypt function to re-encrypt your data keys within a region. GenerateDataKey always returns the data key encrypted and tied to the customer master key that will be used to decrypt it. There is no need to decrypt it twice.

If you decide to use the optional EncryptionContext parameter, you must also store the context in full or at least store enough information along with the encrypted data to be able to reconstruct the context when submitting the ciphertext to the Decrypt API. It is a good practice to choose a context that you can reconstruct on the fly to better secure the ciphertext. For more information about how this parameter is used, see Encryption Context.

To decrypt data, pass the encrypted data key to the Decrypt API. Decrypt uses the associated master key to decrypt the encrypted data key and returns it as plaintext. Use the plaintext data key to locally decrypt your data and then erase the key from memory. You must specify the encryption context, if any, that you specified when you generated the key. The encryption context is logged by CloudTrail, and you can use this log to help track the use of particular data.

Request Syntax

client.generate_data_key(
    KeyId='string',
    EncryptionContext={
        'string': 'string'
    },
    NumberOfBytes=123,
    KeySpec='AES_256'|'AES_128',
    GrantTokens=[
        'string',
    ]
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier, a fully specified ARN to either an alias or a key, or an alias name prefixed by "alias/".

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Alias ARN Example - arn:aws:kms:us-east-1:123456789012:/alias/MyAliasName

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

  • Alias Name Example - alias/MyAliasName

type EncryptionContext

dict

param EncryptionContext

Name/value pair that contains additional data to be authenticated during the encryption and decryption processes that use the key. This value is logged by AWS CloudTrail to provide context around the data encrypted by the key.

  • (string) --

    • (string) --

type NumberOfBytes

integer

param NumberOfBytes

Integer that contains the number of bytes to generate. Common values are 128, 256, 512, and 1024. 1024 is the current limit. We recommend that you use the KeySpec parameter instead.

type KeySpec

string

param KeySpec

Value that identifies the encryption algorithm and key size to generate a data key for. Currently this can be AES_128 or AES_256.

type GrantTokens

list

param GrantTokens

For more information, see Grant Tokens.

  • (string) --

rtype

dict

returns

Response Syntax

{
    'CiphertextBlob': b'bytes',
    'Plaintext': b'bytes',
    'KeyId': 'string'
}

Response Structure

  • (dict) --

    • CiphertextBlob (bytes) --

      Ciphertext that contains the encrypted data key. You must store the blob and enough information to reconstruct the encryption context so that the data encrypted by using the key can later be decrypted. You must provide both the ciphertext blob and the encryption context to the Decrypt API to recover the plaintext data key and decrypt the object.

      If you are using the CLI, the value is Base64 encoded. Otherwise, it is not encoded.

    • Plaintext (bytes) --

      Plaintext that contains the data key. Use this for encryption and decryption and then remove it from memory as soon as possible.

    • KeyId (string) --

      System generated unique identifier of the key to be used to decrypt the encrypted copy of the data key.

RetireGrant (new) Link ¶

Retires a grant. You can retire a grant when you're done using it to clean up. You should revoke a grant when you intend to actively deny operations that depend on it. The following are permitted to call this API:

  • The account that created the grant

  • The RetiringPrincipal , if present

  • The GranteePrincipal , if RetireGrant is a grantee operation

Request Syntax

client.retire_grant(
    GrantToken='string'
)
type GrantToken

string

param GrantToken

[REQUIRED]

Token that identifies the grant to be retired.

returns

None

Decrypt (new) Link ¶

Decrypts ciphertext. Ciphertext is plaintext that has been previously encrypted by using any of the following functions:

  • GenerateDataKey

  • GenerateDataKeyWithoutPlaintext

  • Encrypt

Note that if a caller has been granted access permissions to all keys (through, for example, IAM user policies that grant Decrypt permission on all resources), then ciphertext encrypted by using keys in other accounts where the key grants access to the caller can be decrypted. To remedy this, we recommend that you do not grant Decrypt access in an IAM user policy. Instead grant Decrypt access only in key policies. If you must grant Decrypt access in an IAM user policy, you should scope the resource to specific keys or to specific trusted accounts.

Request Syntax

client.decrypt(
    CiphertextBlob=b'bytes',
    EncryptionContext={
        'string': 'string'
    },
    GrantTokens=[
        'string',
    ]
)
type CiphertextBlob

bytes

param CiphertextBlob

[REQUIRED]

Ciphertext to be decrypted. The blob includes metadata.

type EncryptionContext

dict

param EncryptionContext

The encryption context. If this was specified in the Encrypt function, it must be specified here or the decryption operation will fail. For more information, see Encryption Context.

  • (string) --

    • (string) --

type GrantTokens

list

param GrantTokens

For more information, see Grant Tokens.

  • (string) --

rtype

dict

returns

Response Syntax

{
    'KeyId': 'string',
    'Plaintext': b'bytes'
}

Response Structure

  • (dict) --

    • KeyId (string) --

      ARN of the key used to perform the decryption. This value is returned if no errors are encountered during the operation.

    • Plaintext (bytes) --

      Decrypted plaintext data. This value may not be returned if the customer master key is not available or if you didn't have permission to use it.

PutKeyPolicy (new) Link ¶

Attaches a policy to the specified key.

Request Syntax

client.put_key_policy(
    KeyId='string',
    PolicyName='string',
    Policy='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

type PolicyName

string

param PolicyName

[REQUIRED]

Name of the policy to be attached. Currently, the only supported name is "default".

type Policy

string

param Policy

[REQUIRED]

The policy, in JSON format, to be attached to the key.

returns

None

ListKeyPolicies (new) Link ¶

Retrieves a list of policies attached to a key.

Request Syntax

client.list_key_policies(
    KeyId='string',
    Limit=123,
    Marker='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier, a fully specified ARN to either an alias or a key, or an alias name prefixed by "alias/".

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Alias ARN Example - arn:aws:kms:us-east-1:123456789012:/alias/MyAliasName

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

  • Alias Name Example - alias/MyAliasName

type Limit

integer

param Limit

Specify this parameter only when paginating results to indicate the maximum number of policies you want listed in the response. If there are additional policies beyond the maximum you specify, the Truncated response element will be set to true.

type Marker

string

param Marker

Use this parameter only when paginating results, and only in a subsequent request after you've received a response where the results are truncated. Set it to the value of the NextMarker in the response you just received.

rtype

dict

returns

Response Syntax

{
    'PolicyNames': [
        'string',
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) --

    • PolicyNames (list) --

      A list of policy names. Currently, there is only one policy and it is named "Default".

      • (string) --

    • NextMarker (string) --

      If Truncated is true, this value is present and contains the value to use for the Marker request parameter in a subsequent pagination request.

    • Truncated (boolean) --

      A flag that indicates whether there are more items in the list. If your results were truncated, you can make a subsequent pagination request using the Marker request parameter to retrieve more policies in the list.

ListKeys (new) Link ¶

Lists the customer master keys.

Request Syntax

client.list_keys(
    Limit=123,
    Marker='string'
)
type Limit

integer

param Limit

Specify this parameter only when paginating results to indicate the maximum number of keys you want listed in the response. If there are additional keys beyond the maximum you specify, the Truncated response element will be set to true.

type Marker

string

param Marker

Use this parameter only when paginating results, and only in a subsequent request after you've received a response where the results are truncated. Set it to the value of the NextMarker in the response you just received.

rtype

dict

returns

Response Syntax

{
    'Keys': [
        {
            'KeyId': 'string',
            'KeyArn': 'string'
        },
    ],
    'NextMarker': 'string',
    'Truncated': True|False
}

Response Structure

  • (dict) --

    • Keys (list) --

      A list of keys.

      • (dict) --

        Contains information about each entry in the key list.

        • KeyId (string) --

          Unique identifier of the key.

        • KeyArn (string) --

          ARN of the key.

    • NextMarker (string) --

      If Truncated is true, this value is present and contains the value to use for the Marker request parameter in a subsequent pagination request.

    • Truncated (boolean) --

      A flag that indicates whether there are more items in the list. If your results were truncated, you can make a subsequent pagination request using the Marker request parameter to retrieve more keys in the list.

ReEncrypt (new) Link ¶

Encrypts data on the server side with a new customer master key without exposing the plaintext of the data on the client side. The data is first decrypted and then encrypted. This operation can also be used to change the encryption context of a ciphertext.

Request Syntax

client.re_encrypt(
    CiphertextBlob=b'bytes',
    SourceEncryptionContext={
        'string': 'string'
    },
    DestinationKeyId='string',
    DestinationEncryptionContext={
        'string': 'string'
    },
    GrantTokens=[
        'string',
    ]
)
type CiphertextBlob

bytes

param CiphertextBlob

[REQUIRED]

Ciphertext of the data to re-encrypt.

type SourceEncryptionContext

dict

param SourceEncryptionContext

Encryption context used to encrypt and decrypt the data specified in the CiphertextBlob parameter.

  • (string) --

    • (string) --

type DestinationKeyId

string

param DestinationKeyId

[REQUIRED]

A unique identifier for the customer master key used to re-encrypt the data. This value can be a globally unique identifier, a fully specified ARN to either an alias or a key, or an alias name prefixed by "alias/".

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Alias ARN Example - arn:aws:kms:us-east-1:123456789012:/alias/MyAliasName

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

  • Alias Name Example - alias/MyAliasName

type DestinationEncryptionContext

dict

param DestinationEncryptionContext

Encryption context to be used when the data is re-encrypted.

  • (string) --

    • (string) --

type GrantTokens

list

param GrantTokens

For more information, see Grant Tokens.

  • (string) --

rtype

dict

returns

Response Syntax

{
    'CiphertextBlob': b'bytes',
    'SourceKeyId': 'string',
    'KeyId': 'string'
}

Response Structure

  • (dict) --

    • CiphertextBlob (bytes) --

      The re-encrypted data. If you are using the CLI, the value is Base64 encoded. Otherwise, it is not encoded.

    • SourceKeyId (string) --

      Unique identifier of the key used to originally encrypt the data.

    • KeyId (string) --

      Unique identifier of the key used to re-encrypt the data.

DisableKeyRotation (new) Link ¶

Disables rotation of the specified key.

Request Syntax

client.disable_key_rotation(
    KeyId='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

returns

None

EnableKeyRotation (new) Link ¶

Enables rotation of the specified customer master key.

Request Syntax

client.enable_key_rotation(
    KeyId='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

returns

None

DeleteAlias (new) Link ¶

Deletes the specified alias.

Request Syntax

client.delete_alias(
    AliasName='string'
)
type AliasName

string

param AliasName

[REQUIRED]

The alias to be deleted.

returns

None

DisableKey (new) Link ¶

Marks a key as disabled, thereby preventing its use.

Request Syntax

client.disable_key(
    KeyId='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

returns

None

GenerateDataKeyWithoutPlaintext (new) Link ¶

Returns a data key encrypted by a customer master key without the plaintext copy of that key. Otherwise, this API functions exactly like GenerateDataKey. You can use this API to, for example, satisfy an audit requirement that an encrypted key be made available without exposing the plaintext copy of that key.

Request Syntax

client.generate_data_key_without_plaintext(
    KeyId='string',
    EncryptionContext={
        'string': 'string'
    },
    KeySpec='AES_256'|'AES_128',
    NumberOfBytes=123,
    GrantTokens=[
        'string',
    ]
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier, a fully specified ARN to either an alias or a key, or an alias name prefixed by "alias/".

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Alias ARN Example - arn:aws:kms:us-east-1:123456789012:/alias/MyAliasName

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

  • Alias Name Example - alias/MyAliasName

type EncryptionContext

dict

param EncryptionContext

Name:value pair that contains additional data to be authenticated during the encryption and decryption processes.

  • (string) --

    • (string) --

type KeySpec

string

param KeySpec

Value that identifies the encryption algorithm and key size. Currently this can be AES_128 or AES_256.

type NumberOfBytes

integer

param NumberOfBytes

Integer that contains the number of bytes to generate. Common values are 128, 256, 512, 1024 and so on. We recommend that you use the KeySpec parameter instead.

type GrantTokens

list

param GrantTokens

For more information, see Grant Tokens.

  • (string) --

rtype

dict

returns

Response Syntax

{
    'CiphertextBlob': b'bytes',
    'KeyId': 'string'
}

Response Structure

  • (dict) --

    • CiphertextBlob (bytes) --

      Ciphertext that contains the wrapped data key. You must store the blob and encryption context so that the key can be used in a future decrypt operation.

      If you are using the CLI, the value is Base64 encoded. Otherwise, it is not encoded.

    • KeyId (string) --

      System generated unique identifier of the key to be used to decrypt the encrypted copy of the data key.

UpdateKeyDescription (new) Link ¶

Updates the description of a key.

Request Syntax

client.update_key_description(
    KeyId='string',
    Description='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

type Description

string

param Description

[REQUIRED]

New description for the key.

returns

None

CreateGrant (new) Link ¶

Adds a grant to a key to specify who can access the key and under what conditions. Grants are alternate permission mechanisms to key policies. For more information about grants, see Grants in the developer guide. If a grant is absent, access to the key is evaluated based on IAM policies attached to the user.

  • ListGrants

  • RetireGrant

  • RevokeGrant

Request Syntax

client.create_grant(
    KeyId='string',
    GranteePrincipal='string',
    RetiringPrincipal='string',
    Operations=[
        'Decrypt'|'Encrypt'|'GenerateDataKey'|'GenerateDataKeyWithoutPlaintext'|'ReEncryptFrom'|'ReEncryptTo'|'CreateGrant'|'RetireGrant',
    ],
    Constraints={
        'EncryptionContextSubset': {
            'string': 'string'
        },
        'EncryptionContextEquals': {
            'string': 'string'
        }
    },
    GrantTokens=[
        'string',
    ]
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier or the fully specified ARN to a key.

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

type GranteePrincipal

string

param GranteePrincipal

[REQUIRED]

Principal given permission by the grant to use the key identified by the keyId parameter.

type RetiringPrincipal

string

param RetiringPrincipal

Principal given permission to retire the grant. For more information, see RetireGrant.

type Operations

list

param Operations

List of operations permitted by the grant. This can be any combination of one or more of the following values:

  • Decrypt

  • Encrypt

  • GenerateDataKey

  • GenerateDataKeyWithoutPlaintext

  • ReEncryptFrom

  • ReEncryptTo

  • CreateGrant

  • RetireGrant

  • (string) --

type Constraints

dict

param Constraints

Specifies the conditions under which the actions specified by the Operations parameter are allowed.

  • EncryptionContextSubset (dict) -- The constraint equals the full encryption context.

    • (string) --

      • (string) --

  • EncryptionContextEquals (dict) -- The constraint contains additional key/value pairs that serve to further limit the grant.

    • (string) --

      • (string) --

type GrantTokens

list

param GrantTokens

For more information, see Grant Tokens.

  • (string) --

rtype

dict

returns

Response Syntax

{
    'GrantToken': 'string',
    'GrantId': 'string'
}

Response Structure

  • (dict) --

    • GrantToken (string) --

      For more information, see Grant Tokens.

    • GrantId (string) --

      Unique grant identifier. You can use the GrantId value to revoke a grant.

GenerateRandom (new) Link ¶

Generates an unpredictable byte string.

Request Syntax

client.generate_random(
    NumberOfBytes=123
)
type NumberOfBytes

integer

param NumberOfBytes

Integer that contains the number of bytes to generate. Common values are 128, 256, 512, 1024 and so on. The current limit is 1024 bytes.

rtype

dict

returns

Response Syntax

{
    'Plaintext': b'bytes'
}

Response Structure

  • (dict) --

    • Plaintext (bytes) --

      Plaintext that contains the unpredictable byte string.

DescribeKey (new) Link ¶

Provides detailed information about the specified customer master key.

Request Syntax

client.describe_key(
    KeyId='string'
)
type KeyId

string

param KeyId

[REQUIRED]

A unique identifier for the customer master key. This value can be a globally unique identifier, a fully specified ARN to either an alias or a key, or an alias name prefixed by "alias/".

  • Key ARN Example - arn:aws:kms:us-east-1:123456789012:key/12345678-1234-1234-1234-123456789012

  • Alias ARN Example - arn:aws:kms:us-east-1:123456789012:/alias/MyAliasName

  • Globally Unique Key ID Example - 12345678-1234-1234-123456789012

  • Alias Name Example - alias/MyAliasName

rtype

dict

returns

Response Syntax

{
    'KeyMetadata': {
        'AWSAccountId': 'string',
        'KeyId': 'string',
        'Arn': 'string',
        'CreationDate': datetime(2015, 1, 1),
        'Enabled': True|False,
        'Description': 'string',
        'KeyUsage': 'ENCRYPT_DECRYPT'
    }
}

Response Structure

  • (dict) --

    • KeyMetadata (dict) --

      Metadata associated with the key.

      • AWSAccountId (string) --

        Account ID number.

      • KeyId (string) --

        Unique identifier for the key.

      • Arn (string) --

        Key ARN (Amazon Resource Name).

      • CreationDate (datetime) --

        Date the key was created.

      • Enabled (boolean) --

        Value that specifies whether the key is enabled.

      • Description (string) --

        The description of the key.

      • KeyUsage (string) --

        A value that specifies what operation(s) the key can perform.