I have a lambda function which is trying to read data from elastic search running in an ec2 machine. Both of them are in the same VPC, subnet and have the same security group assigned to it. The Lambda can't seem to access the elastic search instance.
const AWS = require('aws-sdk');
const elasticsearch = require('elasticsearch');
exports.handler = async function (event, context, callback) {
const client = new elasticsearch.Client({
host: 'public_dns:9200',
httpAuth: 'user:password'
});
let self = this;
client.search({
index: 'index_name',
scroll: '30s',
size: 10000,
body: {
query: {
match_all: {}
}
}
})
.then(response => {
self.responseString = response.hits.hits;
console.log(response.hits.hits);
})
.catch(error => {
console.error(error);
});
const responseData = {
statusCode: 200,
body: JSON.stringify({
message: self.responseString
})
};
callback(null, responseData);
};
The error i get from lambda is
2023-02-06T23:19:54.890Z fcd62836-4fe3-4c6a-9871-ee70668ba07c ERROR StatusCodeError: Request Timeout after 30000ms
at /var/task/node_modules/elasticsearch/src/lib/transport.js:397:9
at Timeout.<anonymous> (/var/task/node_modules/elasticsearch/src/lib/transport.js:429:7)
at listOnTimeout (node:internal/timers:559:17)
at processTimers (node:internal/timers:502:7) {
status: undefined,
displayName: 'RequestTimeout',
body: undefined
Any tips on how to debug this would be highly appreciated. Note: I do not wish to make the elastic search endpoint accessible to public.