amazon-web-services - Dynamodb boto3 dynamodbstreams get_records
问题描述
我需要创建一个方法来允许我检索由我的 dynamodb 表中的流存储的记录。我以前在我的表基础中激活流,此外还执行了一些更新来生成这些流记录。
现在,为了更深入地了解如何实现这一点,我正在查看AWS 文档。因此,在boto3中,理论上可以检索这些记录的完整功能。
我一直在尝试部署该方法get_records
,因为按照结构我可能会传递一个 ShardID。但后来我不知道如何生成该分片 ID。我尝试运行 a来获取分片并将其用作最终获得分片迭代器并触发describe_stream
所需的 shardID ,但使用的 Shard ID 不是正确的。这是我的代码:get_shard_iterator
get_records
import boto3
client = boto3.resource('dynamodb')
clients = boto3.client('dynamodbstreams')
table = client.Table('songs')
# How I suppose I can get a shard ID
response = clients.describe_stream(
StreamArn='arn:aws:dynamodb:region:account:table/songs/stream/2018-09-04T00:03:49.742',
Limit=3, )
print(response['StreamDescription']['Shards'])
# Now I pass the shard ID to get the shared iterator
response = clients.get_shard_iterator(
ShardId='00000001536019433750-85f234d8',
ShardIteratorType='TRIM_HORIZON',
StreamArn='arn:aws:dynamodb:region:account:table/songs/stream/2018-09-04T00:03:49.742',
)
print(response)
错误:
botocore.errorfactory.ResourceNotFoundException:调用GetShardIterator操作时发生错误(ResourceNotFoundException):未找到请求的资源:分片不存在
非常感谢!
解决方案
假设您的是单个分片流,请尝试以下步骤获取 ShardId :
import boto3
client = boto3.resource('dynamodb')
clients = boto3.client('dynamodbstreams')
table = client.Table('songs')
# How I suppose I can get a shard ID
response = clients.describe_stream(
StreamArn='arn:aws:dynamodb:region:account:table/songs/stream/2018-09-04T00:03:49.742',
Limit=3, )
print(response['StreamDescription']['Shards'][0]['ShardId'])
# Now I pass the shard ID to get the shared iterator
response = clients.get_shard_iterator(
ShardId=response['StreamDescription']['Shards'][0]['ShardId'],
ShardIteratorType='TRIM_HORIZON',
StreamArn='arn:aws:dynamodb:region:account:table/songs/stream/2018-09-04T00:03:49.742',
)
print(response)
推荐阅读
- json - 如何仅为 serde_json 实现自定义序列化?
- excel - Excel VBA根据整个工作表中的多项选择来更改单元格值
- swift - Swift - 如何在不切断内容的情况下在视图之间创建空间
- r - 将字符串日期 AM/PM 转换为 R 中结构“%d-%Y-%m %I:%M:%S %p”的日期格式
- laravel - 像 elseif 和 else 一样使用三元运算符
- docker - docker commit 需要至少 1 个和最多 2 个参数
- flutter - Flutter 后台 Firebase 通信
- sql - 如何使用 SQL 根据 2 列上的条件删除重复项
- c# - 向 SciChart BoxAnnotation 添加更多手柄
- excel - 如何使用通配符查看工作表?通配符不起作用