访问和管理AWS云服务,如Amazon S3(简单存储服务)、Amazon EC2(弹性计算云)和Amazon DynamoDB(NoSQL数据库服务
天问 02bb4b4374 Update 'README.md' | 8 months ago | |
---|---|---|
README.md | 8 months ago | |
boto3_util.py | 9 months ago |
访问和管理AWS云服务,如Amazon S3(简单存储服务)、Amazon EC2(弹性计算云)和Amazon DynamoDB(NoSQL数据库服务)
pip install boto3
s3 = boto3.client('s3', endpoint_url=config.AWS_ENDPOINT_URL_S3)
def upload(name: str, data: str):
gzip_buffer = BytesIO()
with gzip.GzipFile(mode='wb', fileobj=gzip_buffer) as gzip_file:
gzip_file.write(data.encode('utf-8'))
return s3.put_object(
Bucket=config.BUCKET_NAME,
Key=name,
Body=gzip_buffer.getvalue(),
ContentEncoding='gzip',
ContentType='application/json'
)
def download(name: str) -> str:
response = s3.get_object(Bucket=config.BUCKET_NAME, Key=name)
gzip_content = response['Body'].read()
return gzip.decompress(gzip_content)