Boto3
我啥时候遇到的¶
- 在用localstack跑模型的时候,需要连接到S3服务。
boto3是 AWS提供的官方 Python SDK,可以让你用 Python 代码直接操作各种 AWS 服务,比如 S3。
用法¶
- 建立S3连接
-
返回
s3_client对象,之后就能用它下载、上传、列出 bucket 等操作。 -
下载文件
bucket(str): The name of the bucket to download from.key(str): The name of the key to download from.-
filename(str): The path to the file to download to. -
上传文件
file_obj(a file-like object): A file-like object to upload.bucket(str): The name of the bucket to upload to.-
key(str): The name of the key to upload to. -
测试连接
- 不需要参数
- 如果成功返回,说明连接没问题,会以dict形式返回所有的 bucket 列表
boto3S3客户端官方API文档:https://boto3.amazonaws.com/v1/documentation/api/1.9.42/reference/services/s3.html?utm_source=chatgpt.com#client