Python boto3 API调用Storage Lens配置

关于S3 Storage Lens功能介绍如下。

官方文档(中文):使用 Amazon S3 Storage Lens 存储统计管理工具评估您的存储活动和使用情况

https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/storage_lens.html

官方文档(中文):利用控制台和 API 使用 Amazon S3 Storage Lens 存储统计管理工具

https://docs.aws.amazon.com/zh_cn/AmazonS3/latest/userguide/S3LensExamples.html

对应的Python Boto3 SDK(英文):https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3control.html

调用的方法叫做client = boto3.client('s3control')

在Client方法声明参数问题上,可参考如下文档Client参数集合(英文):

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/core/session.html#boto3.session.Session.client

如果正确配置AWSCLI的Access Key/Secret Key,那么Python3和Boto3是可以自动识别密钥和中国区域的,不需要额外声明S3的Endpoint了。

以调用get_storage_lens_configuration为例,写法参考这里:

https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3control/client/get_storage_lens_configuration.html

我写了一段代码,只输入required参数,其他可选参数不输入。本机实现配置了AWSCLI和AKSK密钥。测试通过。代码如下:

import boto3

client = boto3.client('s3control')

response = client.get_storage_lens_configuration(
ConfigId='default-account-dashboard',
AccountId='420029960748'
)

print(response)

在北京区域是正常工作。工作正常的截图如下。