[英]Kinesis to Lambda - Parsing Data
I'm following this tutorial to push data from my API Gateway to a Kinesis stream : 我正在按照本教程将数据从我的API网关推送到Kinesis流:
http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-kinesis.html#api-gateway-get-and-add-records-to-stream http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-kinesis.html#api-gateway-get-and-add-records-to-stream
I have my Body Mapping Template setup as..... 我将我的身体映射模板设置为......
{
"StreamName": "my-stream-name",
"Data": "$util.base64Encode($input.path('$.Data'))",
"PartitionKey": "$input.path('$.PartitionKey')"
}
...and have put the following in the Request Body of an API test... ...并将以下内容放在API测试的请求主体中......
{
"Data": {
"Foo": "A",
"Bar": "B"
},
"PartitionKey": "some key"
}
I've then created a Lambda Function which has a trigger set up against the same Kinesis Stream. 然后我创建了一个Lambda函数,它具有针对相同Kinesis Stream设置的触发器。 However, I'm struggling to decode/deserialise the records coming in from Kinesis. 但是,我正在努力解码/反序列化来自Kinesis的记录。
exports.handler = (event, context, callback) => {
event.Records.forEach(function(record) {
let payload = JSON.parse(Buffer(record.kinesis.data, 'base64').toString('ascii'))
});
};
It seems that the data is being serialised to Kinesis in a non-JSON format. 似乎数据以非JSON格式被序列化为Kinesis。 The value for record.kinesis.data
in the forEach loop is forEach循环中record.kinesis.data
的值是
e0Zvbz1BLCBCYXI9Qn0= e0Zvbz1BLCBCYXI9Qn0 =
...which when push through Buffer(record.kinesis.data, 'base64').toString('ascii') ...当推送缓冲区时(record.kinesis.data,'base64')。toString('ascii')
returns as 返回为
{Foo=A, Bar=B} {Foo = A,Bar = B}
not 不
{"Foo":"A", "Bar":"B"} {“Foo”:“A”,“Bar”:“B”}
Main aim is obviously to get payload to in a state where I can say console.log(payload.Foo)
主要目的显然是将有效负载置于我可以说console.log(payload.Foo)
Any hints as to what I should be doing/looking for would be appreciated. 任何关于我应该做什么/寻找什么的提示都将不胜感激。
For anyone else out there 对于那里的任何人
I had my Body Mapping Template setup as..... 我将我的身体映射模板设置为......
{
"StreamName": "my-stream-name",
"Data": "$util.base64Encode($input.path('$.Data'))",
"PartitionKey": "$input.path('$.PartitionKey')"
}
Now changed to handle the json.... 现在改为处理json ....
{
"StreamName": "my-stream-name",
"Data": "$util.base64Encode($input.json('$.Data'))",
"PartitionKey": "$input.path('$.PartitionKey')"
}
where... 哪里...
($input.json('$.Data'))
is the change :) 是改变:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.