【发布时间】:2018-12-13 09:00:23
【问题描述】:
当我使用 put 操作将数据对象插入 aws firhose 流时,它工作正常。由于我的 firehose 流上启用了 lambda 函数。因此调用了 lambda 函数但给了我一个输出结构响应错误:
"errorMessage":"Invalid output structure: Please check your function and make sure the processed records contain valid result status of Dropped, Ok, or ProcessingFailed."
所以现在我已经像这样创建了我的 lambda 函数来制作正确的输出结构:
import base64
import json
print('Loading function')
def lambda_handler(event, context):
output=[]
print('event'+str(event))
for record in event['records']:
payload = base64.b64decode(record['data'])
print('payload'+str(payload))
payload=base64.b64encode(payload)
output_record={
'recordId':record['recordId'],
'result': 'Ok',
'data': base64.b64encode(json.dumps('hello'))
}
output.append(output_record)
return { 'records': output }
现在我在将“数据”字段编码为时遇到以下错误
"errorMessage": "a bytes-like object is required, not 'str'",
如果我将 'hello' 更改为 b'hello' 之类的字节,则会出现以下错误:
"errorMessage": "Object of type bytes is not JSON serializable",
【问题讨论】:
-
解决方案'data': base64.b64encode('hello'.encode('utf-8')).decode('utf-8').处理/更新后的数据可以作为字符串传递在将数据发送回队列时代替单词“hello”对数据进行编码
标签: python-3.x amazon-web-services aws-lambda amazon-kinesis amazon-kinesis-firehose