{"size": 961, "ext": "js", "max_stars_repo_path": "elasticsearch-publisher/src/lambda.js", "max_stars_repo_name": "NPCentral/desole-collector-backend", "max_stars_repo_stars_event_min_datetime": "2018-05-14T08:46:45.000Z", "max_stars_repo_stars_event_max_datetime": "2020-08-27T21:38:04.000Z", "max_issues_repo_path": "elasticsearch-publisher/src/lambda.js", "max_issues_repo_name": "NPCentral/desole-collector-backend", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "elasticsearch-publisher/src/lambda.js", "max_forks_repo_name": "NPCentral/desole-collector-backend", "max_forks_repo_forks_event_min_datetime": "2018-06-30T13:33:43.000Z", "max_forks_repo_forks_event_max_datetime": "2021-03-20T12:21:52.000Z"}
{"max_stars_count": 63, "max_issues_count": null, "max_forks_count": 7, "avg_line_length": 24.641025641, "max_line_length": 63, "alphanum_fraction": 0.6732570239}
'use strict';
const AWS = require('aws-sdk'),
	elasticsearch = require('elasticsearch'),
	awsES = require('http-aws-es'),
	util = require('util'),
	parseSNSEvent = require('@desole/common/src/parse-sns-event'),
	myCredentials = new AWS.EnvironmentCredentials('AWS'),
	index = process.env.ES_INDEX_NAME,
	documentType = process.env.ES_DOCUMENT_TYPE,
	client = new elasticsearch.Client({
		host: process.env.ES_DOMAIN_NAME,
		connectionClass: awsES,
		amazonES: {
			region: process.env.AWS_REGION,
			credentials: myCredentials
		}
	}),
	storeSingleEvent = event => {
		const params = {
			index: index,
			type: documentType,
			id: event.id,
			body: event
		};
		return new Promise((resolve, reject) => {
			client.create(params, (err, result) => {
				if (err) {
					return reject(err);
				}
				resolve(result);
			});
		});
	};

exports.handler = (event) => {
	const records = parseSNSEvent(event);
	return Promise.all(records.map(storeSingleEvent));
};
