安装Boto3,执行如下命令:
shell
python -m venv .venv
. .venv/bin/activate
python -m pip install boto3
创建配置文件,执行如下命令:
shell
mkdir -p ~/.aws
touch ~/.aws/credentials
touch ~/.aws/config
编辑 ~/.aws/credentials,样例如下:
[default]
aws_access_key_id = YOUR_KEY
aws_secret_access_key = YOUR_SECRET
编辑 ~/.aws/config,样例如下:
[default]
region=us-east-1
使用Boto3,访问S3服务,样例代码如下:
python
import boto3
s3 = boto3.resource('s3')
for bucket in s3.buckets.all():
print(bucket.name)