1

I've walked through the IoT tutorial in the AWS console for setting up a Linux/Java device, which downloads a zip file, and ultimately uses the code here: https://github.com/aws/aws-iot-device-sdk-java. When I run the start.sh script from the zip, I see an UnknownHostException, and the script fails.

Cert file:../java-thing.cert.pem Private key: ../java-thing.private.key
Sep 21, 2017 10:23:11 PM com.amazonaws.services.iot.client.mqtt.AwsIotMqttConnectionListener onFailure
WARNING: Connect request failure
MqttException (0) - java.net.UnknownHostException: a2vnfud9kry2r9.iot.us-east-1.amazonaws.com
        at org.eclipse.paho.client.mqttv3.internal.ExceptionHelper.createMqttException(ExceptionHelper.java:38)
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:664)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.net.UnknownHostException: a2vnfud9kry2r9.iot.us-east-1.amazonaws.com
        at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:184)
        at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
        at java.net.Socket.connect(Socket.java:589)
        at sun.security.ssl.SSLSocketImpl.connect(SSLSocketImpl.java:668)
        at org.eclipse.paho.client.mqttv3.internal.TCPNetworkModule.start(TCPNetworkModule.java:70)
        at org.eclipse.paho.client.mqttv3.internal.SSLNetworkModule.start(SSLNetworkModule.java:86)
        at org.eclipse.paho.client.mqttv3.internal.ClientComms$ConnectBG.run(ClientComms.java:650)
        ... 1 more

Diagnosing the connectivity, as suggested in the official docs, has no issue; it connects just fine:

openssl s_client -connect a2vnfud9kry2r9.iot.us-east-1.amazonaws.com:8443 -CAfile root-CA.crt -cert java-thing.cert.pem -key java-thing.private.key

What's also odd is that pinging the client endpoint works, but other tools like telnet fail to resolve the hostname.

What am I doing wrong?

noelob
  • 460
  • 5
  • 14
  • Could this be an issue with IPv6 on Linux? I've tried the same tutorial on OSX and it works fine. – noelob Sep 26 '17 at 05:01

1 Answers1

0

I figured out how to work around this: set -Djava.net.preferIPv4Stack=true.

The IoT endpoints in AWS support both IPv6 and IPv4, and, out of the box, Java will prefer IPv6. From the docs:

The Java networking stack first checks whether IPv6 is supported on the underlying OS. If IPv6 is supported, it tries to use the IPv6 stack. More specifically, on dual-stack systems, it creates an IPv6 socket.

Seems like perhaps something in my Ubuntu network config is not set up right for IPv6 to work properly. If anyone can shed some light on why, that would be awesome.

My issue is probably linked to this one.

noelob
  • 460
  • 5
  • 14