We recently started encountering a strange error in a process that was working fine earlier. In one of our lambda functions, we upload a file from ephemeral storage to an S3 bucket.
await s3Client.send(
new PutObjectCommand({
Bucket: bucket,
Key: `${id}.mp4`,
Body: createReadStream(outputFile),
ContentType: 'video/mp4',
Tagging: 'test=true',
}),
);
The call is failing with the error
ERROR Invoke Error
{
"errorType": "TimeoutError",
"errorMessage": "socket hang up",
"code": "ECONNRESET",
"name": "TimeoutError",
"stack": [
"TimeoutError: socket hang up",
" at connResetException (node:internal/errors:720:14)",
" at TLSSocket.socketOnEnd (node:_http_client:525:23)",
" at TLSSocket.emit (node:events:529:35)",
" at endReadableNT (node:internal/streams/readable:1400:12)",
" at process.processTicksAndRejections (node:internal/process/task_queues:82:21)"
]
}
The file being transferred was around 50 MB in size but up until now we had never faced any issue with much bigger files as well.
I tried looking up this error but did not find any definitive solution or the root cause of it. As a trial, we switched to SDK version 2 and used the putObject
command like this
await s3ClientV2.putObject({
Bucket: bucket,
Key: `${id}.mp4`,
Body: createReadStream(outputFile),
ContentType: 'video/mp4',
Tagging: 'test=true',
}).promise();
Which worked like a charm. I don’t understand if it is a bug in AWS SDK v3 or something missing at our end but this used to work perfectly earlier and is breaking now.