Skip to content

Commit 8e44484

Browse files
committed
docs: derive allowed discovery region from ARN rather than hard-coding it
1 parent ad25893 commit 8e44484

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

examples/src/keyring/aws_kms/discovery_decrypt_in_region_only.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,17 @@ def run(aws_kms_cmk, source_plaintext):
5252
# Create the keyring that determines how your data keys are protected.
5353
encrypt_keyring = KmsKeyring(generator_key_id=aws_kms_cmk)
5454

55+
# Extract the region from the CMK ARN.
56+
decrypt_region = aws_kms_cmk.split(":", 4)[3]
57+
5558
# Create the KMS discovery keyring that we will use on decrypt.
5659
#
5760
# Because we do not specify any key IDs, this keyring is created in discovery mode.
5861
#
5962
# The client supplier that we specify here will only supply clients for the specified region.
6063
# The keyring only attempts to decrypt data keys if it can get a client for that region,
6164
# so this keyring will now ignore any data keys that were encrypted under a CMK in another region.
62-
decrypt_keyring = KmsKeyring(client_supplier=AllowRegionsClientSupplier(allowed_regions=["us-west-2"]))
65+
decrypt_keyring = KmsKeyring(client_supplier=AllowRegionsClientSupplier(allowed_regions=[decrypt_region]))
6366

6467
# Encrypt your plaintext data.
6568
ciphertext, _encrypt_header = aws_encryption_sdk.encrypt(

0 commit comments

Comments
 (0)