简体   繁体   中英

Read a KMS encrypted file from S3

How can I use boto3 resource to read a KMS encrypted file from S3 bucket?

Below is the snippet that I am using to read a non-encrypted file -

s3 = boto3.resource('s3')
obj = s3.Object(bucket_name, key)
body = obj.get()['Body'].read()
print(' body = {}'.format(body))

There's a helpful answer at Do I need to specify the AWS KMS key when I download a KMS-encrypted object from Amazon S3?

No, you don't need to specify the AWS KMS key ID when you download an SSE-KMS-encrypted object from an S3 bucket. Instead, you need the permission to decrypt the AWS KMS key.

So, you don't need to provide KMS info on a GetObject request (which is what the boto3 resource-level methods are doing under the covers), unless you're doing CMK . You just need to have permission to access the KMS key for decryption. S3/KMS will do the rest for you.

You can configure the IAM policy associated with the Lambda function's IAM role per the linked article.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM