python - Boto3 按时间戳从 Kinesis 流读取

标签 python boto3 amazon-kinesis

我正在尝试从 Kinesis 流中读取数据。如果我使用 ShardIteratorType AT_SEQUENCE_NUMBERLATEST,它就可以正常工作。但是,如果我尝试使用 AT_TIMESTAMP 类型并设置 TIMESTAMP,boto3 会提示:

  File "/usr/local/lib/python2.7/site-packages/botocore/validate.py", line 269, in serialize_to_request
    raise ParamValidationError(report=report.generate_report())
botocore.exceptions.ParamValidationError: Parameter validation failed:
Unknown parameter in input: "Timestamp", must be one of: StreamName, ShardId, ShardIteratorType, StartingSequenceNumber

获取shard_id的代码如下。

import boto3
from datetime import datetime

client = boto3.client('kinesis')

shard_it = client.get_shard_iterator(
    StreamName='foo',
    ShardId='shardId-000000000000',
    ShardIteratorType='AT_TIMESTAMP',
    Timestamp=datetime(2015, 1, 1)
)

有人有这方面的经验吗?

根据API docs参数存在。

最佳答案

看起来您的 boto3 不是最新的,因此 boto3 客户端库无法识别新参数。请运行 $ sudo pip install -u boto3 或类似命令。

顺便说一句,Timestamp 参数接受以下两项:

  • 日期时间对象(例如datetime.datetime)
  • UNIX 时间戳(例如 time.time)

关于python - Boto3 按时间戳从 Kinesis 流读取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37273062/

相关文章:

python - 简单的返回函数,还有什么更 Pythonic 的?

python - 使用对数概率的复杂性 - 朴素贝叶斯文本分类器

python - 我如何使用 sqlalchemy 来利用 sqlite list 类型/类型亲和性?

python - 如何将资源的引用传递给 CFN 模板中的 python 字典?

json - 读取由 Amazon Kinesis Firehose 流写入 s3 的数据

json - Kinesis Firehose 在没有分隔符逗号的情况下将 JSON 对象放入 S3

java - 使用 Java 的 Kinesis firehose 数据转换

python - 通过 Python SDK 获取 azure 规模集中所有虚拟机的名称

python - 调用PutObject操作时发生错误(AccessDenied): Access Denied python

amazon-web-services - 如何调用也在 AWS SAM 模板中定义的另一个 lambda 函数?