function postDocumentToES()

in infrastructure/function/src/s3AudioStreamingLambdaFunction/index.js [59:87]


function postDocumentToES(doc, id, context) {
    return new Promise(() => {
        const req = new AWS.HttpRequest(endpoint);
        req.method = 'POST';
        req.path += esDomain.index + '/' + esDomain.doctype;
        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);
            });
        });
    });
}