Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Error: getaddrinfo EAI_AGAIN using Amazon S3 SDK

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;
        }
like image 793
NIKHIL C M Avatar asked Dec 14 '18 06:12

NIKHIL C M


People also ask

What does Getaddrinfo Eai_again mean?

EAI_AGAIN is a DNS lookup timed out error, means it is a network connectivity error or proxy related error.

How do I fix Getaddrinfo Enotfound?

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.


1 Answers

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.

like image 180
byteslash Avatar answered Sep 18 '22 09:09

byteslash