Skip to content
This repository was archived by the owner on Oct 9, 2021. It is now read-only.

Added content-type #70

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions ElasticSearchLambda/ZombieWorkshopSearchIndexing.js
Original file line number Diff line number Diff line change
@@ -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,28 +41,26 @@ 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);
req.region = esDomain.region;
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 = '';
httpResp.on('data', function (chunk) {
respBody += chunk;
});
httpResp.on('end', function (chunk) {
console.log('Response: ' + respBody);
context.succeed('Lambda added document ' + doc);
});
}, function(err) {