I am getting an error from Amazon S3 SDK in my Node.js Project as given below.
{ Error: getaddrinfo EAI_AGAIN ***.s3-accelerate.amazonaws.com:443
at Object._errnoException (util.js:992:11)
at errnoException (dns.js:55:15)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:92:26)
message: 'getaddrinfo EAI_AGAIN ***.s3-accelerate.amazonaws.com:443',
code: 'NetworkingError',
errno: 'EAI_AGAIN',
syscall: 'getaddrinfo',
hostname: '***.s3-accelerate.amazonaws.com',
host: '***.s3-accelerate.amazonaws.com',
port: 443,
region: 'us-east-1',
retryable: true,
time: 2018-12-14T05:46:18.649Z }
error: There was an error viewing your album: getaddrinfo EAI_AGAIN ***.s3-accelerate.amazonaws.com:443
I know it is a DNS issue error. But the error happening occasionally. If I try running the code, again and again, this error may not show.
The S3 is in the us-east region and I am accessing from Asia. But as far as I know, Amazon S3 region have no part in this.
Part of my code is given below :
FYI: I promisified S3 SDK
const s3 = new AWS.S3({useAccelerateEndpoint: true});
const bucket_name = s3Storage.bucketName;
s3getImageV2: async function (albumPhotosKey) {
albumPhotosKey = albumPhotosKey.toString();
try {
const s3 = new AWSP.S3({useAccelerateEndpoint: true});
const bucket_name = s3Storage.bucketName;
if (!albumPhotosKey) {
return {
status: false,
message: 'Album name is not given.'
};
}
const data = await listImageObjects(s3, bucket_name, albumPhotosKey);
var photos = [];
logger.debug('S3:data.Contents: ', data.Contents.length);
for (let i = 0; i < data.Contents.length; i++) {
const photo = data.Contents[i];
if (photo.Key.endsWith("/")) continue;
const params = {
Bucket: bucket_name,
Key: photo.Key,
Expires: config.cache.ttl || 86400
};
logger.silly(`iteration:, ${i}`);
// skiniq:s3
const resp = await s3.getSignedUrlProm('getObject', params);
photos.push(resp);
}
logger.debug('S3:OUTPUT: ', photos);
return photos;
} catch (e) {
console.error(e);
return null;
}
EAI_AGAIN is a DNS lookup timed out error, means it is a network connectivity error or proxy related error.
The error getaddrinfo ENOTFOUND localhost is caused by Webpack cannot found localhost address. To solve it, open the terminal: sudo nano /etc/hosts. Add following into the hosts file and save it.
i had the same issue lately, and after very long hours googling about it I've found a solution which stated that one should remove the REGION parameter from the initialization and you should be fine. I did it and worked. I hope this helps any one in trouble with this error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With