3
3
"""
4
4
This example sets up the KMS MRK (multi-region key) Keyring
5
5
6
- KMS MRK keyring interacts with AWS Key Management Service (AWS KMS) to create, encrypt,
7
- and decrypt data keys using AWS KMS defined Customer Master Keys (CMKs ).
6
+ The AWS Key Management Service (AWS KMS) MRK keyring interacts with AWS KMS to
7
+ create, encrypt, and decrypt data keys with multi-region AWS KMS keys (MRKs ).
8
8
This example creates a KMS MRK Keyring and then encrypts a custom input EXAMPLE_DATA
9
9
with an encryption context. This example also includes some sanity checks for demonstration:
10
10
1. Ciphertext and plaintext data are not the same
42
42
43
43
44
44
def encrypt_and_decrypt_with_keyring (
45
- encrypt_kms_key_id : str ,
46
- decrypt_kms_key_id : str ,
47
- encrypt_region : str ,
48
- decrypt_region : str
45
+ mrk_key_id_encrypt : str ,
46
+ mrk_replica_key_id_decrypt : str ,
47
+ default_region : str ,
48
+ second_region : str
49
49
):
50
- """Demonstrate an encrypt/decrypt cycle using an AWS KMS keyring.
51
-
52
- Usage: encrypt_and_decrypt_with_keyring(encrypt_kms_key_id,
53
- decrypt_kms_key_id,
54
- encrypt_region,
55
- decrypt_region)
56
- :param encrypt_kms_key_id: KMS Key identifier for the KMS key you want to use
57
- for encryption of your data keys.
58
- :type encrypt_kms_key_id: string
59
- :param decrypt_kms_key_id: KMS Key identifier for the KMS key you want to use
60
- for decryption of your data keys.
61
- :type decrypt_kms_key_id: string
62
- :param encrypt_region: AWS Region for encryption of your data keys
63
- :type encrypt_region: string
64
- :param decrypt_region: AWS Region for decryption of your data keys
65
- :type decrypt_region: string
50
+ """Demonstrate an encrypt/decrypt cycle using an AWS KMS MRK keyring.
51
+
52
+ Usage: encrypt_and_decrypt_with_keyring(mrk_key_id_encrypt,
53
+ mrk_replica_key_id_decrypt,
54
+ default_region,
55
+ second_region)
56
+ :param mrk_key_id_encrypt: KMS Key identifier for the KMS key located in your
57
+ default region, which you want to use for encryption of your data keys
58
+ :type mrk_key_id_encrypt: string
59
+ :param mrk_replica_key_id_decrypt: KMS Key identifier for the KMS key KMS Key
60
+ that is a replica of the `mrk_key_id_encrypt` in a second region, which you
61
+ want to use for decryption of your data keys
62
+ :type mrk_replica_key_id_decrypt: string
63
+ :param default_region: AWS Region for encryption of your data keys
64
+ :type default_region: string
65
+ :param second_region: AWS Region for decryption of your data keys
66
+ :type second_region: string
66
67
67
68
For more information on KMS Key identifiers, see
68
69
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
@@ -96,10 +97,10 @@ def encrypt_and_decrypt_with_keyring(
96
97
)
97
98
98
99
# Create a boto3 client for KMS in the first region.
99
- encrypt_kms_client = boto3 .client ('kms' , region_name = encrypt_region )
100
+ encrypt_kms_client = boto3 .client ('kms' , region_name = default_region )
100
101
101
102
encrypt_keyring_input : CreateAwsKmsMrkKeyringInput = CreateAwsKmsMrkKeyringInput (
102
- kms_key_id = encrypt_kms_key_id ,
103
+ kms_key_id = mrk_key_id_encrypt ,
103
104
kms_client = encrypt_kms_client
104
105
)
105
106
@@ -123,10 +124,10 @@ def encrypt_and_decrypt_with_keyring(
123
124
# to the second region. This example assumes you have already replicated your key
124
125
125
126
# Create a boto3 client for KMS in the second region.
126
- decrypt_kms_client = boto3 .client ('kms' , region_name = decrypt_region )
127
+ decrypt_kms_client = boto3 .client ('kms' , region_name = second_region )
127
128
128
129
decrypt_keyring_input : CreateAwsKmsMrkKeyringInput = CreateAwsKmsMrkKeyringInput (
129
- kms_key_id = decrypt_kms_key_id ,
130
+ kms_key_id = mrk_replica_key_id_decrypt ,
130
131
kms_client = decrypt_kms_client
131
132
)
132
133
0 commit comments