function postDocumentToES()

in infrastructure/function/src/transcriptToESFunction/index.js [36:62]


function postDocumentToES(doc, id, context) {
    const req = new AWS.HttpRequest(endpoint);
    req.method = 'POST';
    req.path += esDomain.index + '/' + esDomain.doctype + '/' + id;
    req.region = esDomain.region;
    req.body = JSON.stringify(doc);
    req.headers['presigned-expires'] = false;
    req.headers['Host'] = endpoint.host;
    req.headers['Content-Type'] = 'application/json';
    req.headers['Content-Length'] = req.body.length;
    const signer = new AWS.Signers.V4(req, 'es');
    const creds = new AWS.EnvironmentCredentials('AWS');
    signer.addAuthorization(creds, new Date());
    const client = new AWS.HttpClient();
    client.handleRequest(req, null, function(httpResp) {
        let body = '';
        httpResp.on('data', function (chunk) {
            body += chunk;
        });
        httpResp.on('end', function () {
            context.succeed({'status': 1, 'message': body});
            console.log(body);
        }, function(err) {
            console.log("ERR", err);
        });
    });
}