I have node/express apis project. from node/express, I connect to S3 bucket/ RDS mysql to perform different operations.
local
In local machine, everything works fine. No exception, no error !! It always return data. I performed different operations thousand times and never got a single error.
AWS Once local development is done, I move all apis to one AWS lambda function. In other words, entire node/express apis project to one AWS lambda function.
Here is my tech stack at cloud side:
HTTP API Gateway <=> Lambda function <=> S3 bucket
||
||
=========> RDS MySQL
FE makes API calls, it goes to HTTP API to Lambda to S3 bucket/Mysql.
As I mentioned, It works absolutely fine in local but on AWS side I get intermittent error Unhandled Promise Rejection
I have one api which gets me some data from S3 bucket. When I call it, it fetches data successfully and then after that when I make other api call, SOMETIMES ONLY, it throws promise rejection error. IT IS NOT EVEN HITTING THE NEXT CONTROLLER as shown below.
As you can see in pic, API request executed successfully. And then, form UI when I make other API call, it fails sometimes.
YES, I use promise to connect to S3 bucket.
S3-Service.js
const AWS = require("aws-sdk");
const environment = require("../../config");
AWS.config.update({
accessKeyId: environment.aws.accessKeyId,
secretAccessKey: environment.aws.secretAccessKey,
region: environment.aws.region
});
const S3 = new AWS.S3();
const getBufferFromS3 = (file) => {
const bucketName = environment.S3.bucketName;
const objectKey = file;
return S3.getObject({ Bucket: bucketName, Key: objectKey }).promise();
};
const listBucketContent = (filePath, bucketName) => {
const params = { Bucket: bucketName, Prefix: filePath };
return S3.listObjects(params).promise();
}
...
As I mentioned, yes exception handling is added but still I can't seem to capture this failure in it. Trying to resolve since past few days but I really have no idea how to get to the problem.
NOTE: It usually occurs after some operation on S3 bucket.