【发布时间】:2017-03-11 08:40:55
【问题描述】:
我正在使用 boto3(1.4.4 版)与 Amazon 的 Kinesis API 通信:
import boto3
kinesis = boto3.client('kinesis')
# write a record with data '\x08' to the test stream
response = kinesis.put_record(StreamName='test', Data=b'\x08', PartitionKey='foobar')
print(response['ResponseMetadata']['HTTPStatusCode']) # 200
# now read from the test stream
shard_it = kinesis.get_shard_iterator(StreamName="test", ShardId='shardId-000000000000', ShardIteratorType="LATEST")["ShardIterator"]
response = kinesis.get_records(ShardIterator=shard_it, Limit=10)
print(response['ResponseMetadata']['HTTPStatusCode']) # 200
print(response['Records']) # []
当我使用没有 \x 转义的任何数据对其进行测试时,我能够按预期取回记录。 Amazon boto3's doc 表示“数据块可以是任何类型的数据;例如,来自日志文件的片段、地理/位置数据、网站点击流数据等。”那么为什么带有\x 转义字符的消息会丢失?在将数据发送到 kinesis 之前,我需要 '\x08'.encode('string_escape') 吗?
如果您有兴趣,我在消息数据中有 \x08 之类的字符,因为我正在尝试将序列化的协议缓冲区消息写入 Kinesis 流。
【问题讨论】:
-
您是说您的 Lambda 函数永远不会收到包含二进制数据的消息吗?
-
@garnaat 我没有使用任何 lambda 函数,我只是在写入流后使用 python kinesis 客户端从流中读取。我的意思是,尽管消息写入似乎成功,但当我从流中读取时,无论我在写入后等待多长时间,都没有记录。虽然我在没有
\x转义的情况下写了一条消息后能够阅读记录。
标签: python python-2.7 protocol-buffers boto3 amazon-kinesis