访问和管理AWS云服务,如Amazon S3(简单存储服务)、Amazon EC2(弹性计算云)和Amazon DynamoDB(NoSQL数据库服务

天问 02bb4b4374 Update 'README.md' 3 weeks ago
README.md 02bb4b4374 Update 'README.md' 3 weeks ago
boto3_util.py 829da82da0 Add 'boto3_util.py' 1 month ago

README.md

boto3

访问和管理AWS云服务,如Amazon S3(简单存储服务)、Amazon EC2(弹性计算云)和Amazon DynamoDB(NoSQL数据库服务)

Usage

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)