使用 boto3 进行 GCP 保留设置
我正在使用 python boto3 包访问 AWS S3 和 GCP 存储桶。 这些存储桶已为其各自的存储桶设置了对象锁定/保留。 是否有一个通用的包/SDK 可以获取锁定/保留详细信息。
session = boto3.session.Session(aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
region_name=region_name)
s3_client = session.client('s3', endpoint_url=endpoint)
head = s3_client.head_bucket(Bucket=bucket_name)
result = s3_client.get_object_lock_configuration(Bucket=bucket_name)
此代码块适用于 AWS S3,但会引发 GCP 存储桶异常。 抛出异常:
[DEBUG] Response body: b"<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code>
<Message>Invalid argument.</Message><Details>Invalid query parameter(s): [object-lock]</Details></Error>" 2022-03-03 20:16:37,111 botocore.hooks
[DEBUG] Event needs-retry.s3.GetObjectLockConfiguration: calling handler <botocore.retryhandler.RetryHandler object at 0x7f518264a310> 2022-03-03 20:16:37,112 botocore.retryhandler
[DEBUG] No retry needed. 2022-03-03 20:16:37,113 botocore.hooks
[DEBUG] Event needs-retry.s3.GetObjectLockConfiguration: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x7f518264a370>>
An error occurred (InvalidArgument) when calling the GetObjectLockConfiguration operation: Invalid argument.
谢谢!!
I am using the python boto3 package to access AWS S3 and GCP buckets.
These buckets have object lock/retention set to their respective buckets.
Is there a common packge/SDK that would fetch the lock/retention details.
session = boto3.session.Session(aws_access_key_id=access_key,
aws_secret_access_key=secret_key,
region_name=region_name)
s3_client = session.client('s3', endpoint_url=endpoint)
head = s3_client.head_bucket(Bucket=bucket_name)
result = s3_client.get_object_lock_configuration(Bucket=bucket_name)
This code block works for AWS S3 but throws exception for GCP buckets.
Exception thrown:
[DEBUG] Response body: b"<?xml version='1.0' encoding='UTF-8'?><Error><Code>InvalidArgument</Code>
<Message>Invalid argument.</Message><Details>Invalid query parameter(s): [object-lock]</Details></Error>" 2022-03-03 20:16:37,111 botocore.hooks
[DEBUG] Event needs-retry.s3.GetObjectLockConfiguration: calling handler <botocore.retryhandler.RetryHandler object at 0x7f518264a310> 2022-03-03 20:16:37,112 botocore.retryhandler
[DEBUG] No retry needed. 2022-03-03 20:16:37,113 botocore.hooks
[DEBUG] Event needs-retry.s3.GetObjectLockConfiguration: calling handler <bound method S3RegionRedirector.redirect_from_error of <botocore.utils.S3RegionRedirector object at 0x7f518264a370>>
An error occurred (InvalidArgument) when calling the GetObjectLockConfiguration operation: Invalid argument.
Thank you!!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Google 云存储在 SDK 中有一组单独的命令 - gsutil。
您可以使用 retention 命令获取详细信息。
还有一个 API,允许从 存储桶 获取多个信息和对象。
在
fields
参数中发送retentionPolicy
、retentionPeriod
或effectiveTime
以仅过滤您感兴趣的值。Google Cloud storage has a separate set of commands within the SDK - gsutil.
You can use retention command to obtain the details.
There is also an API that allows fetching multiple information from buckets and objects.
Send
retentionPolicy
,retentionPeriod
oreffectiveTime
infields
parameter to filter only the values you are interested in.