Question:
I setup an API using amazon api gateway and want to put data into Kinesis streams. Amazon API gateway has inbuilt support for it. But when I try to put JSON data it gives “Serialization exception”.
1 2 3 4 5 6 7 8 9 10 11 12 |
var data = {"ua_platform":"iPhone","ua_browsercodename":"Mozilla","ua_browserlanguage":"en-us","ua_header":"Mozilla\/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit\/601.1.46 (KHTML, like Gecko) Version\/9.0 Mobile\/13B143 Safari\/601.1","ua_browsername":"Netscape","key":"livestream_hindi",,"datetime_ut":"1458711871","datetime_dt":"2016-03-23","value":"15","source":"0","browser":"Mobile Safari-9.0.","os":"iOS-9.1.","device_detail":"iPhone Apple iPhone"}; var json = JSON.stringify(data); var params = { 'ContentType': 'application/json', 'Access-Control-Allow-Headers': 'Content-Type,X-Amz-Date,Authorization,X-Api-Key,X-Amz-Security-Token' }; var body = { "Data": json, "StreamName": "XXXXXX", "PartitionKey": "XXXX" }; |
After this I make a put request
1 2 3 4 5 6 7 8 9 10 |
apigClient.functionPut(params, body, additionalParams) .then(function(result) { // This is where you would put a success callback console.log("success"); }) .catch(function(result) { // This is where you would put an error callback console.log("catch"); }); |
The API gives 200 ok along with the serialization exception. It is stated in put request the “Data” key in body variable will accept only “blob” type. Now I also tried converting JSON data to BLOB but no luck at all.
I am not able to figure out what I am doing wrong. Please help.
Answer:
There’s a walkthrough of how to set up API Gateway in front of Kinesis in the official AWS docs at http://docs.aws.amazon.com/apigateway/latest/developerguide/integrating-api-with-aws-services-kinesis.html