Amazon web services Dynamodb BOT3 Dynamodb流获取记录

Amazon web services Dynamodb BOT3 Dynamodb流获取记录,amazon-web-services,amazon-dynamodb,boto3,amazon-dynamodb-streams,Amazon Web Services,Amazon Dynamodb,Boto3,Amazon Dynamodb Streams,我需要创建一个方法来检索dynamodb表中由流存储的记录。我以前在我的表中激活了流,此外还进行了一些更新来生成这些流记录 现在,深入研究如何实现这一点,我正在检查。所以,在那里有一个满的 理论上可能检索这些记录的功能 我一直在尝试部署方法get_records,因为按照结构我可能会传递一个ShardID。但是我不知道如何生成该碎片ID。我尝试运行descripe\u stream来获取碎片,并按照get\u shard\u iterator中的要求使用该碎片,以最终获取shard iterat

我需要创建一个方法来检索dynamodb表中由流存储的记录。我以前在我的表中激活了流,此外还进行了一些更新来生成这些流记录

现在,深入研究如何实现这一点,我正在检查。所以,在那里有一个满的 理论上可能检索这些记录的功能

我一直在尝试部署方法
get_records
,因为按照结构我可能会传递一个ShardID。但是我不知道如何生成该碎片ID。我尝试运行
descripe\u stream
来获取碎片,并按照
get\u shard\u iterator
中的要求使用该碎片,以最终获取shard iterator并触发
get\u记录
,但使用的碎片ID并不正确。这是我的密码:

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:发生错误 (ResourceNotFoundException)调用GetShardeTerator时 操作:未找到请求的资源:碎片不存在


非常感谢

假设您的是单个碎片流,请尝试以下步骤获得碎片:

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)

您调用了descripe_stream()并打印了碎片。假设实际返回了一个或多个碎片,为什么不使用结果中的碎片呢?@jarmod非常感谢您的回答。尽管如此,我还是使用了ShardID,但它一直在向我显示这个特定的ShardID不存在。如果descripe_stream()没有返回ID为“0000000 1536019433750-85f234d8”的shard,那么可能该ID无效,或者它与不同的流相关联。当我打印
打印时(响应['StreamDescription']['Shards'))
我想获取该碎片id,但当我使用该id获取碎片迭代器时,我发现该碎片id不存在:(我不确定“我想获取该碎片id”是什么意思。id“0000000 1536019433750-85f234d8”是否在响应中?能否为您的问题添加描述流()响应的打印输出。