I'm running the following in AWS Lambda, inside my handler function:
URL url = new URL("www.sfsuperiorcourt.org");
URLConnection connection = url.openConnection();
connection.setConnectTimeout(2000);
connection.connect();
This is inside a handler function. When running it locally, it's fine, and connects immediately, and I'm able to retrieve the contents. On Lambda, it fails with java.net.SocketTimeoutException: connect timed out
. If I don't set a timeout on the connection, Lambda itself times out after 10s. This happens consistently, and on my local machine, it consistently succeeds, so I'm sure it's not a problem with the site I'm connecting to.
I'm able to do IP address resolution successfully on Lambda, so that's not the problem. Seems entirely related to opening the socket.
Maybe my role needs permission to open a socket? Any other obvious things like that? Any known way to debug the TCP layer?