/aws-iot-core-websockets

A library that handles connecting third-party websockets based MQTT clients to AWS IoT Core.

Primary LanguageJavaApache License 2.0Apache-2.0

AWS IoT Core Websockets

Build Status Open Issues License

A library that handles connecting third-party websockets based MQTT clients to AWS IoT Core.

Why MQTT over WebSockets?

MQTT over WebSockets allows you to use SigV4 credentials. This means that you can use this library to connect to AWS IoT Core, without certificates, assuming that you have a way to get SigV4 credentials. For normal IAM users this can be from .aws/config's access key and secret key ID, or it could be from the EC2 instance meta-data service so you can use an instance profile, or it could be from the AWS Secure Token Service so you can ship temporary credentials to other systems over any secure delivery mechanism that you have set up already.

Can I use SigV4 credentials with normal MQTT?

Not as of 2021-05-04 according to the AWS IoT documentation.

How do I include it in my Gradle project?

  1. Add the jitpack repo to the repositories section

    maven { url 'https://jitpack.io' }
    
  2. Add the dependency version (replace x.y.z with the appropriate version from the JitPack site)

    def awsIotCoreWebsocketsVersion = 'x.y.z'
    
  3. Add the dependency to the dependencies section

    compile "com.github.awslabs:aws-iot-core-websockets:$awsIotCoreWebsocketsVersion"
    

How do I use it?

Check out an example in the IoT reference architectures repo.

Is there a really simple example snippet to get me started?

Of course, all you have to do after including the library to get an MQTT client with your IAM credentials is this:

        mqttOverWebsocketsProvider = new BasicMqttOverWebsocketsProvider();
        String uuid = UUID.randomUUID().toString();
        clientId = ImmutableClientId.builder().clientId(uuid).build();
        mqttClient = mqttOverWebsocketsProvider.getMqttClient(clientId);

License

This library is licensed under the Apache 2.0 License.