跳转到主要内容

boto3的辅助工具

项目描述

boto3_helpers 是一个Python库,旨在为AWS boto3 包的一些函数提供更平滑的接口。

您知道如何安装它

pip install boto3-helpers

您是否见过有人犯这个错误?

from boto3 import resource as boto3_resource
from boto3.dynamodb.conditions import Key

# Don't do this; you'll miss out if there is more than one page
ddb_table = boto3.resource('dynamodb').Table('example-table')
resp = ddb_table.query(
    KeyConditionExpression=Key('username').eq('johndoe')
)
for item in resp.get('Items', []):
    print(item)

他们应该这么做

from boto3 import resource as boto3_resource
from boto3.dynamodb.conditions import Key

# Loop through all the pages
ddb_table = boto3.resource('dynamodb').Table('example-table')
kwargs = {'KeyConditionExpression': Key('username').eq('johndoe')}
while True:
    resp = ddb_table.query(**kwargs)
    for item in resp.get('Items', []):
        print(item)
    if 'LastEvaluatedKey' not in resp:
        break
    kwargs['ExclusiveStartKey'] = resp['LastEvaluatedKey']

使用 boto3_helpers,您可以更轻松地做正确的事情

from boto3 import resource as boto3_resource
from boto3.dynamodb.conditions import Key
from boto3_helpers.dynamodb import query_table

ddb_table = boto3.resource('dynamodb').Table('example-table')
for item in query_table(
    ddb_table, KeyConditionExpression=Key('username').eq('johndoe')
):
    print(item)

此包为AWS中的几个类似操作提供辅助函数,例如

  • 分页浏览S3列表

  • 更新DynamoDB中的条目

  • 使用STS假定角色

  • 使用SQS发送和删除消息

  • 从CloudWatch拉取指标数据

有关更多信息,请参阅最新文档

项目详情


下载文件

下载适用于您的平台文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源分发

boto3-helpers-2.3.0.tar.gz (31.6 kB 查看哈希值)

上传于

构建发行版

boto3_helpers-2.3.0-py3-none-any.whl (24.6 kB 查看哈希)

上传于 Python 3

由以下支持