KMS

Table of Contents

Client

class KMS.Client

A low-level client representing AWS Key Management Service (KMS):

import boto3

client = boto3.client('kms')

These are the available methods:

can_paginate(operation_name)

Check if an operation can be paginated.

Parameters:operation_name (string) -- The operation name. This is the same name as the method name on the client. For example, if the method name is create_foo, and you'd normally invoke the operation as client.create_foo(**kwargs), if the create_foo operation can be paginated, you can use the call client.get_paginator("create_foo").
Returns:True if the operation can be paginated, False otherwise.
create_alias(**kwargs)

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).

To associate an alias with a different key, call UpdateAlias .

Note that you cannot create or update an alias that represents a key in another account.

Request Syntax

response = client.create_alias(
    AliasName='string',
    TargetKeyId='string'
)
Parameters:
  • AliasName (string) --

    [REQUIRED]

    String that contains the display name. The name must start with the word "alias" followed by a forward slash (alias/). Aliases that begin with "alias/AWS" are reserved.

  • TargetKeyId (string) --

    [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-1234-123456789012
Returns:

None

create_grant(**kwargs)

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

response = 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',
    ]
)
Parameters:
  • KeyId (string) --

    [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-1234-123456789012
  • GranteePrincipal (string) --

    [REQUIRED]

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

  • RetiringPrincipal (string) -- Principal given permission to retire the grant. For more information, see RetireGrant .
  • 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
    • RetireGrant
    • (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) --
  • GrantTokens (list) --

    For more information, see Grant Tokens .

    • (string) --
Return type:

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.

create_key(**kwargs)

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

response = client.create_key(
    Policy='string',
    Description='string',
    KeyUsage='ENCRYPT_DECRYPT'
)
Parameters:
  • Policy (string) -- Policy to be attached to the key. This is required and delegates back to the account. The key is the root of trust.
  • Description (string) -- Description of the key. We recommend that you choose a description that helps your customer decide whether the key is appropriate for a task.
  • KeyUsage (string) -- Specifies the intended use of the key. Currently this defaults to ENCRYPT/DECRYPT, and only symmetric encryption and decryption are supported.
Return type:

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.

decrypt(**kwargs)

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

response = client.decrypt(
    CiphertextBlob=b'bytes',
    EncryptionContext={
        'string': 'string'
    },
    GrantTokens=[
        'string',
    ]
)
Parameters:
  • CiphertextBlob (bytes) --

    [REQUIRED]

    Ciphertext to be decrypted. The blob includes metadata.

  • EncryptionContext (dict) --

    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) --
  • GrantTokens (list) --

    For more information, see Grant Tokens .

    • (string) --
Return type:

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.

delete_alias(**kwargs)

Deletes the specified alias. To associate an alias with a different key, call UpdateAlias .

Request Syntax

response = client.delete_alias(
    AliasName='string'
)
Parameters:AliasName (string) --

[REQUIRED]

The alias to be deleted. The name must start with the word "alias" followed by a forward slash (alias/). Aliases that begin with "alias/AWS" are reserved.

Returns:None
describe_key(**kwargs)

Provides detailed information about the specified customer master key.

Request Syntax

response = client.describe_key(
    KeyId='string'
)
Parameters:KeyId (string) --

[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-1234-123456789012
  • Alias Name Example - alias/MyAliasName
Return type: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.

disable_key(**kwargs)

Marks a key as disabled, thereby preventing its use.

Request Syntax

response = client.disable_key(
    KeyId='string'
)
Parameters:KeyId (string) --

[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-1234-123456789012
Returns:None
disable_key_rotation(**kwargs)

Disables rotation of the specified key.

Request Syntax

response = client.disable_key_rotation(
    KeyId='string'
)
Parameters:KeyId (string) --

[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-1234-123456789012
Returns:None
enable_key(**kwargs)

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

Request Syntax

response = client.enable_key(
    KeyId='string'
)
Parameters:KeyId (string) --

[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-1234-123456789012
Returns:None
enable_key_rotation(**kwargs)

Enables rotation of the specified customer master key.

Request Syntax

response = client.enable_key_rotation(
    KeyId='string'
)
Parameters:KeyId (string) --

[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-1234-123456789012
Returns:None
encrypt(**kwargs)

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

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

    [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-1234-123456789012
    • Alias Name Example - alias/MyAliasName
  • Plaintext (bytes) --

    [REQUIRED]

    Data to be encrypted.

  • EncryptionContext (dict) --

    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) --
  • GrantTokens (list) --

    For more information, see Grant Tokens .

    • (string) --
Return type:

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.

generate_data_key(**kwargs)

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

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

    [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-1234-123456789012
    • Alias Name Example - alias/MyAliasName
  • EncryptionContext (dict) --

    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) --
  • NumberOfBytes (integer) -- 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.
  • KeySpec (string) -- Value that identifies the encryption algorithm and key size to generate a data key for. Currently this can be AES_128 or AES_256.
  • GrantTokens (list) --

    For more information, see Grant Tokens .

    • (string) --
Return type:

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.

generate_data_key_without_plaintext(**kwargs)

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

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

    [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-1234-123456789012
    • Alias Name Example - alias/MyAliasName
  • EncryptionContext (dict) --

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

    • (string) --
      • (string) --
  • KeySpec (string) -- Value that identifies the encryption algorithm and key size. Currently this can be AES_128 or AES_256.
  • NumberOfBytes (integer) -- 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.
  • GrantTokens (list) --

    For more information, see Grant Tokens .

    • (string) --
Return type:

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.

generate_presigned_url(ClientMethod, Params=None, ExpiresIn=3600, HttpMethod=None)

Generate a presigned url given a client, its method, and arguments

Parameters:
  • ClientMethod (string) -- The client method to presign for
  • Params (dict) -- The parameters normally passed to ClientMethod.
  • ExpiresIn (int) -- The number of seconds the presigned url is valid for. By default it expires in an hour (3600 seconds)
  • HttpMethod (string) -- The http method to use on the generated url. By default, the http method is whatever is used in the method's model.
Returns:

The presigned url

generate_random(**kwargs)

Generates an unpredictable byte string.

Request Syntax

response = client.generate_random(
    NumberOfBytes=123
)
Parameters:NumberOfBytes (integer) -- 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.
Return type:dict
Returns:Response Syntax
{
    'Plaintext': b'bytes'
}

Response Structure

  • (dict) --
    • Plaintext (bytes) --

      Plaintext that contains the unpredictable byte string.

get_key_policy(**kwargs)

Retrieves a policy attached to the specified key.

Request Syntax

response = client.get_key_policy(
    KeyId='string',
    PolicyName='string'
)
Parameters:
  • KeyId (string) --

    [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-1234-123456789012
  • PolicyName (string) --

    [REQUIRED]

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

Return type:

dict

Returns:

Response Syntax

{
    'Policy': 'string'
}

Response Structure

  • (dict) --

    • Policy (string) --

      A policy document in JSON format.

get_key_rotation_status(**kwargs)

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

Request Syntax

response = client.get_key_rotation_status(
    KeyId='string'
)
Parameters:KeyId (string) --

[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-1234-123456789012
Return type:dict
Returns:Response Syntax
{
    'KeyRotationEnabled': True|False
}

Response Structure

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

Create a paginator for an operation.

Parameters:operation_name (string) -- The operation name. This is the same name as the method name on the client. For example, if the method name is create_foo, and you'd normally invoke the operation as client.create_foo(**kwargs), if the create_foo operation can be paginated, you can use the call client.get_paginator("create_foo").
Raises OperationNotPageableError:
 Raised if the operation is not pageable. You can use the client.can_paginate method to check if an operation is pageable.
Return type:L{botocore.paginate.Paginator}
Returns:A paginator object.
get_waiter(waiter_name)
list_aliases(**kwargs)

Lists all of the key aliases in the account.

Request Syntax

response = client.list_aliases(
    Limit=123,
    Marker='string'
)
Parameters:
  • Limit (integer) -- 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.
  • Marker (string) -- 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.
Return type:

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.

list_grants(**kwargs)

List the grants for a specified key.

Request Syntax

response = client.list_grants(
    KeyId='string',
    Limit=123,
    Marker='string'
)
Parameters:
  • KeyId (string) --

    [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-1234-123456789012
  • Limit (integer) -- 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.
  • Marker (string) -- 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.
Return type:

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.

list_key_policies(**kwargs)

Retrieves a list of policies attached to a key.

Request Syntax

response = client.list_key_policies(
    KeyId='string',
    Limit=123,
    Marker='string'
)
Parameters:
  • KeyId (string) --

    [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-1234-123456789012
    • Alias Name Example - alias/MyAliasName
  • Limit (integer) -- 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.
  • Marker (string) -- 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.
Return type:

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.

list_keys(**kwargs)

Lists the customer master keys.

Request Syntax

response = client.list_keys(
    Limit=123,
    Marker='string'
)
Parameters:
  • Limit (integer) -- 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.
  • Marker (string) -- 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.
Return type:

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.

put_key_policy(**kwargs)

Attaches a policy to the specified key.

Request Syntax

response = client.put_key_policy(
    KeyId='string',
    PolicyName='string',
    Policy='string'
)
Parameters:
  • KeyId (string) --

    [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-1234-123456789012
  • PolicyName (string) --

    [REQUIRED]

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

  • Policy (string) --

    [REQUIRED]

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

Returns:

None

re_encrypt(**kwargs)

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.

Unlike other actions, ReEncrypt is authorized twice - once as ReEncryptFrom on the source key and once as ReEncryptTo on the destination key. We therefore recommend that you include the "action":"kms:ReEncrypt*" statement in your key policies to permit re-encryption from or to the key. The statement is included automatically when you authorize use of the key through the console but must be included manually when you set a policy by using the PutKeyPolicy function.

Request Syntax

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

    [REQUIRED]

    Ciphertext of the data to re-encrypt.

  • SourceEncryptionContext (dict) --

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

    • (string) --
      • (string) --
  • DestinationKeyId (string) --

    [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-1234-123456789012
    • Alias Name Example - alias/MyAliasName
  • DestinationEncryptionContext (dict) --

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

    • (string) --
      • (string) --
  • GrantTokens (list) --

    For more information, see Grant Tokens .

    • (string) --
Return type:

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.

retire_grant(**kwargs)

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

The grant to retire must be identified by its grant token or by a combination of the key ARN and the grant ID. A grant token is a unique variable-length base64-encoded string. A grant ID is a 64 character unique identifier of a grant. Both are returned by the CreateGrant function.

Request Syntax

response = client.retire_grant(
    GrantToken='string',
    KeyId='string',
    GrantId='string'
)
Parameters:
  • GrantToken (string) -- Token that identifies the grant to be retired.
  • KeyId (string) --

    A unique identifier for the customer master key associated with the grant. This value can be a globally unique identifier or a fully specified ARN of the 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-1234-123456789012
  • GrantId (string) --

    Unique identifier of the grant to be retired. The grant ID is returned by the CreateGrant function.

    • Grant ID Example - 0123456789012345678901234567890123456789012345678901234567890123
Returns:

None

revoke_grant(**kwargs)

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

Request Syntax

response = client.revoke_grant(
    KeyId='string',
    GrantId='string'
)
Parameters:
  • KeyId (string) --

    [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-1234-123456789012
  • GrantId (string) --

    [REQUIRED]

    Identifier of the grant to be revoked.

Returns:

None

update_alias(**kwargs)

Updates an alias to associate it with a different 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).

An alias is not a property of a key. Therefore, an alias can be associated with and disassociated from an existing key without changing the properties of the key.

Note that you cannot create or update an alias that represents a key in another account.

Request Syntax

response = client.update_alias(
    AliasName='string',
    TargetKeyId='string'
)
Parameters:
  • AliasName (string) -- [REQUIRED] String that contains the name of the alias to be modifed. The name must start with the word "alias" followed by a forward slash (alias/). Aliases that begin with "alias/AWS" are reserved.
  • TargetKeyId (string) --

    [REQUIRED]

    Unique identifier of the customer master key to be associated with the alias. This value can be a globally unique identifier or the fully specified ARN of 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-1234-123456789012
Returns:

None

update_key_description(**kwargs)

Updates the description of a key.

Request Syntax

response = client.update_key_description(
    KeyId='string',
    Description='string'
)
Parameters:
  • KeyId (string) --

    [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-1234-123456789012
  • Description (string) --

    [REQUIRED]

    New description for the key.

Returns:

None