I have a nodejs express server setup on Digital Ocean droplet. I have an api which is hitting the following function to read data from aws s3. This api is going into pending state and giving 504 gateway timeout error. But if I restart my server the things work fine. Apart from this api all the other apis are working fine on the server.
// configuration setup
const configuration = {
credentials: {
accessKeyId: process.env.AWS_ACCESS_KEY,
secretAccessKey: process.env.AWS_SECRET_KEY
},
region: process.env.AWS_BUCKET_REGION,
maxAttempts: 3, // retry mechanism
requestTimeout: 60000, // timeout settings
maxConnections: 50, // Example: setting a maximum number of connections
};
//final function
exports.readFileFromS3 = async (file_id) => {
let read_stream = null;
let error = null;
try {
const downloadParams = {
Bucket: process.env.AWS_BUCKET_NAME,
Key: file_id
};
const command = new GetObjectCommand(downloadParams);
const response = await S3Client.send(command);
read_stream = response.Body;
} catch (e) {
error = e;
}
return { read_stream, error };
};
What could be the possible reason for the issue and how should I fix it?