in src/addNode.ts [7:32]
export async function handler(event: ClusterStatusResponse): Promise<AddNodeResponse> {
const targetInstance: Instance = event.targetElasticSearchNode.ec2Instance;
const asg: string = event.asgName;
const elasticsearchClient = new Elasticsearch(targetInstance.id)
return new Promise<AddNodeResponse>((resolve, reject) => {
elasticsearchClient.updateRebalancingStatus("none")
.then(() => detachInstance(targetInstance, asg))
.then(() => elasticsearchClient.getClusterHealth())
.then((clusterStatus: ElasticsearchClusterStatus) => {
const response: AddNodeResponse = {
"asgName": asg,
"targetElasticSearchNode": event.targetElasticSearchNode,
"expectedClusterSize": clusterStatus.number_of_nodes + 1
};
resolve(response);
})
.catch(error => {
console.log(`Failed to add a new node due to: ${error}`);
reject(error);
})
})
}