From 863fa208f995ec3ac1c9c9afc5925da9c0bc4bb4 Mon Sep 17 00:00:00 2001 From: asiffouzi <33208346+asiffouzi@users.noreply.github.com> Date: Thu, 5 Jul 2018 10:27:55 -0400 Subject: [PATCH] Added content-type I have added content type in the postToEs method to resolve the 406 error --- ElasticSearchLambda/ZombieWorkshopSearchIndexing.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/ElasticSearchLambda/ZombieWorkshopSearchIndexing.js b/ElasticSearchLambda/ZombieWorkshopSearchIndexing.js index 9bf7442..57300dd 100644 --- a/ElasticSearchLambda/ZombieWorkshopSearchIndexing.js +++ b/ElasticSearchLambda/ZombieWorkshopSearchIndexing.js @@ -3,8 +3,8 @@ var path = require('path'); /* == Globals == */ var esDomain = { - region: 'us-west-2', - endpoint: 'https://ENDPOINT_HERE', + region: 'replace this with your aws region', + endpoint: 'replace this with your elastic search endpoint', index: 'messages', doctype: 'message' }; @@ -41,7 +41,6 @@ exports.handler = function(event, context) { */ function postToES(doc, context) { var req = new AWS.HttpRequest(endpoint); - console.log('create post request'); req.method = 'POST'; req.path = path.join('/', esDomain.index, esDomain.doctype); @@ -49,12 +48,12 @@ function postToES(doc, context) { req.headers['presigned-expires'] = false; req.headers['Host'] = endpoint.host; req.body = doc; + req.headers['content-type'] = 'application/json'; console.log('Creating the Signer for the post request'); var signer = new AWS.Signers.V4(req , 'es'); // es: service code signer.addAuthorization(creds, new Date()); - console.log('Sending Data'); var send = new AWS.NodeHttpClient(); send.handleRequest(req, null, function(httpResp) { var respBody = ''; @@ -62,7 +61,6 @@ function postToES(doc, context) { respBody += chunk; }); httpResp.on('end', function (chunk) { - console.log('Response: ' + respBody); context.succeed('Lambda added document ' + doc); }); }, function(err) {