How to use the aioboto3.s3.cse function in aioboto3

To help you get started, we’ve selected a few aioboto3 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github terrycain / aioboto3 / tests / View on Github external
async def test_kms_crypto_context_success(event_loop, s3_moto_patch, kms_moto_patch, region, bucket_name, kms_key_alias):
    kms_client = kms_moto_patch('kms', region_name=region)
    resp = await kms_client.create_key(KeyUsage='ENCRYPT_DECRYPT', Origin='AWS_KMS')
    key_id = resp['KeyMetadata']['KeyId']

    await kms_client.create_alias(AliasName=kms_key_alias, TargetKeyId=key_id)

    # Create context
    kms_context = cse.KMSCryptoContext(kms_key_alias, kms_client_args={'region_name': region})
    assert kms_context.kms_key == kms_key_alias

    await kms_context.setup()
    assert kms_context._kms_client is not None

    aes_key, material_description, encrypted_aes_key = await kms_context.get_encryption_aes_key()

    # Material description should denote what key is used
    assert material_description['kms_cmk_id'] == kms_key_alias

    resp = await kms_client.decrypt(CiphertextBlob=encrypted_aes_key, EncryptionContext=material_description)
    assert aes_key == resp['Plaintext']

    await kms_context.close()