Unable to connect to Akka HTTP running on EC2

56 Views Asked by At

I'm moving an Akka HTTP application to AWS and am stumped at this problem. The Akka HTTP server is booted like so:

Http().bindAndHandle(routes, "0.0.0.0", 5377)

The EC2 Instance is started with the aws CLI:

aws ec2 run-instances \
  --count 1 \
  --instance-type t2.micro \
  --key-name variant-us-west-1 \
  --region $region \
  --subnet-id subnet-bc22ebda \
  --security-group-ids sg-0901a32ad173d6aae \
  --image-id ami-0911f75c0510b955d  `#ubuntu-openjdk-17-jre-headless` \
  --output text --query 'Instances[*].InstanceId'

The AMI in question is a private one of mine that has nothing but Java and AWS CLI. The security group sg-0901a32ad173d6aae opens the port in question 5377 for inbound traffic: enter image description here

The running instance does show these same rules in the Security tab: enter image description here

However, when I try to curl it from my local system outside of AWS, I get an error:

curl http://3.101.78.138:5377 
curl: (7) Failed to connect to 3.101.78.138 port 5377 after 19 ms: Couldn't connect to server

I think that the request gets to the server because curl fails fast. If I change to a port that is not open, it takes much longer to time out. So I am suspecting my Akka HTTP configuration, but can't think of anything.

Many thanks in advance!

1

There are 1 best solutions below

0
Igor Urisman On

Tsal Troser's comment got me on the right track. Turns out, Java 17 was binding an IP6 address, even though the interface I am passing to Akka "0.0.0.0" is an IP4 interface. I don't quite understand the network details here, but passing -Djava.net.preferIPv4Stack=true to the runtime solved my problem. Thank you, Gastón Schabas for your comments as well.