使用SSE加密的boto3 generate_presigned_url

时间:2019-12-25 02:17:54

标签: amazon-web-services amazon-s3 encryption boto3

我正在寻找使用boto3和sse加密生成预签名url的示例。

到目前为止,这是我的代码

s3_client = boto3.client('s3',
                                  region_name='ap-south-1',
                                  endpoint_url='http://s3.ap-south-1.amazonaws.com',
                                  config=boto3.session.Config(signature_version='s3v4'),
                                  )
        try:
            response = s3_client.generate_presigned_url('put_object',
                                                        Params={'Bucket': bucket_name,
                                                                'Key': object_name},
                                                        ExpiresIn=expiration)
        except ClientError as e:
            logging.error("In client error exception code")
            logging.error(e)
            return None

我正在努力找到使用SSE加密的正确参数。 我可以使用PUT调用上传文件。我还想知道客户端使用的标头,以坚持sse加密。

1 个答案:

答案 0 :(得分:0)

您可以将条件添加到必须有效的上传预签名URL中。这可能包括x-amz-server-side-encryption

请参阅:Creating a POST Policy - Amazon S3

或者,您可以添加一个存储桶策略,该策略拒绝所有未 加密的请求。

请参阅:How to Prevent Uploads of Unencrypted Objects to Amazon S3 | AWS Security Blog