aws python sdk 常用操作 发表于 2022-07-25 更新于 2023-01-09 上层目录 云平台 , Aws 阅读次数: 环境信息 centos 7 Python3.10 boto3 1.23.2 (pip3 install boto3) S3 相关操作获取 s3 中文件大小from boto3.session import Sessionak = 'XXXXXXX'sk = 'XXXXXXXXXX'region = 'us-west-1'bucketName = 'testBucket'session = Session(aws_access_key_id=ak, aws_secret_access_key=sk, region_name=region)s3 = session.resource('s3')bucket = s3.Bucket(bucketName)obj = bucket.objects.filter(Prefix='filename')for i in obj: if i.size: return i.size EC2 相关操作获取 EC2 instancesimport boto3client = boto3.client('ec2',region_name='ap-east-1',aws_access_key_id='AK',aws_secret_access_key='ty')# 列出所有 Instancesclient.describe_instances()