How to connect other AWS cloud service from an EC2 instance using AWS Javascript SDK?

Stack Overflow Asked by Kumaresh Babu N S on September 3, 2020

I’ve the application deployed on an EC2 instance with an IAM role attached. The instance running inside of private subnet. I’m getting the networking error while trying to listing the buckets from S3 service.

Error: connect ETIMEDOUT
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16) {
errno: -110,
code: 'NetworkingError',
syscall: 'connect',
address: '',
port: 443,
region: 'us-east-1',
hostname: '',
retryable: true,
time: 2020-07-28T05:44:13.678Z
} Error: connect ETIMEDOUT
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1144:16)

2 Answers

Please make sure your instance is able to connect to an S3 endpoint. AWS lists steps to validate network connectivity from EC2 to S3 in their docs. As your instance is running inside a private subnet, please make sure you have one of the following in place:

  • A route table with a default route through a NAT gateway
  • A VPC endpoint.

Answered by berenbums on September 3, 2020

It appears that your situation is:

  • An Amazon EC2 instance in a private subnet
  • An application on the instance needs to access Amazon S3

There are two ways to achieve this:

Option 1: Internet Access

Amazon S3 resides on the Internet. Since the EC2 instance is in a private subnet, it will need to use a NAT Gateway to access the Internet and Amazon S3.

The NAT Gateway should be launched in a public subnet and the Route Table for the private subnet(s) should be updated to send traffic destined for to the NAT Gateway.

Option 2: VPC Endpoint

Alternatively, you can add a VPC Endpoint for S3, which provides a 'short-cut' to communicate with Amazon S3 without going via the Internet.

Answered by John Rotenstein on September 3, 2020

Add your own answers!

Related Questions

numpy array type not supported?

1  Asked on December 30, 2021 by user3066560


Angular Material not applying styles

1  Asked on December 30, 2021 by xeraphim


Calibrating undistortion reducing the size of image

1  Asked on December 30, 2021 by naga-kiran


Spring Boot @Component doesn’t create Beans

2  Asked on December 27, 2021 by bart-kosmala


How to declare a function using assignment operator?

2  Asked on December 27, 2021 by legendrary-saiyan


How can i get {{form}} value with javascript?

2  Asked on December 27, 2021 by user12584812


how to align image and label side by side in html?

3  Asked on December 27, 2021 by jeet-viramgama


Django no module named ‘main’

1  Asked on December 27, 2021 by seyed-moein-ayyoubzadeh


How to get the sum of the values of the JSON Array?

4  Asked on December 27, 2021 by iri0021


Ask a Question

Get help from others!

© 2022 All rights reserved. Sites we Love: PCI Database, MenuIva, UKBizDB, Menu Kuliner, Sharing RPP