I'm having an issue when I try to upload a file to s3 bucket. According to the error message it is a networking error but I'm not sure why I got this error message. This issue does not happen consistently. Can someone help me with this?
CODE
async uploadReportToS3(data){
var uploadParams = {
Bucket: process.env.S3_BUCKET,
Key: "",
Body: ""
}
let errorMsg = {
"ERROR": "",
"exit_code": 1
}
var key = "";
if(data.sub_client && data.sub_client !== ""){
key = process.env.S3_REPORT_FOLDER + data.client + "/" + data.sub_client + "/" + data.report_name;
} else if(data.sub_client == ""){
key = process.env.S3_REPORT_FOLDER + data.client + "/" + data.report_name;
} else if(data.sub_client == null || data.sub_client == undefined){
errorMsg.ERROR = "MISSING SUB CLIENT";
let returnMsg = JSON.stringify(errorMsg);
console.error(returnMsg);
process.exit(1);
}
uploadParams.Key = key;
uploadParams.Body = data.buffer;
await s3.upload(uploadParams, function(error, response){
if(error){
errorMsg.ERROR = error;
let returnMsg = JSON.stringify(errorMsg);
console.error(returnMsg);
process.exit(1);
} else {
let returndata = {
"report_date": data.report_date,
"pdf_path": response.Key,
"error_code": 0
}
let returnedMsg = JSON.stringify(returndata);
console.log(returnedMsg);
process.exit(0);
}
})
}
ERROR MESSAGE
"ERROR":{"message":"write EPIPE","errno":-32,"code":"NetworkingError","syscall":"write","region":"us-east-2","hostname":"test.s3.us-east-2.amazonaws.com","retryable":true,"time":"2020-07-06T19:23:36.775Z","statusCode":400}