Skip to content

Commit aa727ab

Browse files
committed
minor fix
1 parent c5f249e commit aa727ab

File tree

3 files changed

+43
-40
lines changed

3 files changed

+43
-40
lines changed

examples/src/keyrings/aws_kms_mrk_keyring_example.py

+27-26
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""
44
This example sets up the KMS MRK (multi-region key) Keyring
55
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).
88
This example creates a KMS MRK Keyring and then encrypts a custom input EXAMPLE_DATA
99
with an encryption context. This example also includes some sanity checks for demonstration:
1010
1. Ciphertext and plaintext data are not the same
@@ -42,27 +42,28 @@
4242

4343

4444
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
4949
):
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
6667
6768
For more information on KMS Key identifiers, see
6869
https://docs.aws.amazon.com/kms/latest/developerguide/concepts.html#key-id
@@ -96,10 +97,10 @@ def encrypt_and_decrypt_with_keyring(
9697
)
9798

9899
# 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)
100101

101102
encrypt_keyring_input: CreateAwsKmsMrkKeyringInput = CreateAwsKmsMrkKeyringInput(
102-
kms_key_id=encrypt_kms_key_id,
103+
kms_key_id=mrk_key_id_encrypt,
103104
kms_client=encrypt_kms_client
104105
)
105106

@@ -123,10 +124,10 @@ def encrypt_and_decrypt_with_keyring(
123124
# to the second region. This example assumes you have already replicated your key
124125

125126
# 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)
127128

128129
decrypt_keyring_input: CreateAwsKmsMrkKeyringInput = CreateAwsKmsMrkKeyringInput(
129-
kms_key_id=decrypt_kms_key_id,
130+
kms_key_id=mrk_replica_key_id_decrypt,
130131
kms_client=decrypt_kms_client
131132
)
132133

examples/src/keyrings/aws_kms_mrk_multi_keyring_example.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@
33
"""
44
This example sets up the KMS MRK Multi Keyring
55
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).
8-
This example creates a KMS MRK Multi Keyring and then encrypts a custom input EXAMPLE_DATA
9-
with an encryption context. This example also includes some sanity checks for demonstration:
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+
This example creates a KMS MRK Multi Keyring using an mrk_key_id (generator) and
9+
a kms_key_id, and then encrypts a custom input EXAMPLE_DATA with an encryption context.
10+
This example also includes some sanity checks for demonstration:
1011
1. Ciphertext and plaintext data are not the same
1112
2. Encryption context is correct in the decrypted message header
1213
3. Decrypted plaintext value matches EXAMPLE_DATA
@@ -138,8 +139,6 @@ def encrypt_and_decrypt_with_keyring(
138139

139140
# Demonstrate that a single AwsKmsMrkKeyring configured with a replica of the MRK from the
140141
# multi-keyring used to encrypt the data is also capable of decrypting the data.
141-
# Not shown in this example: A KMS Keyring created with `kms_key_id` could also
142-
# decrypt this message.
143142
# (This is an example for demonstration; you do not need to do this in your own code.)
144143

145144
# 9. Create a single AwsKmsMrkKeyring with the replica KMS MRK from the second region.
@@ -171,3 +170,6 @@ def encrypt_and_decrypt_with_keyring(
171170
# 12. Demonstrate that the decrypted plaintext is identical to the original plaintext.
172171
# (This is an example for demonstration; you do not need to do this in your own code.)
173172
assert plaintext_bytes_second_region == EXAMPLE_DATA
173+
174+
# Not shown in this example: A KMS Keyring created with `kms_key_id` could also
175+
# decrypt this message.

examples/test/keyrings/test_i_aws_kms_mrk_keyring_example.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010

1111
def test_encrypt_and_decrypt_with_keyring():
1212
"""Test function for encrypt and decrypt using the AWS KMS MRK Keyring example."""
13-
encrypt_kms_key_id = \
13+
mrk_key_id_encrypt = \
1414
"arn:aws:kms:us-east-1:658956600833:key/mrk-80bd8ecdcd4342aebd84b7dc9da498a7"
15-
decrypt_kms_key_id = \
15+
mrk_replica_key_id_decrypt = \
1616
"arn:aws:kms:eu-west-1:658956600833:key/mrk-80bd8ecdcd4342aebd84b7dc9da498a7"
17-
encrypt_region = "us-east-1"
18-
decrypt_region = "eu-west-1"
19-
encrypt_and_decrypt_with_keyring(encrypt_kms_key_id,
20-
decrypt_kms_key_id,
21-
encrypt_region,
22-
decrypt_region)
17+
default_region = "us-east-1"
18+
second_region = "eu-west-1"
19+
encrypt_and_decrypt_with_keyring(mrk_key_id_encrypt,
20+
mrk_replica_key_id_decrypt,
21+
default_region,
22+
second_region)

0 commit comments

Comments
 (0)