Skip to main content

Utility to sign urls for aws mqtt

Project description

Build Status Coverage Status

aws_signv4_mqtt

Functions to generate aws signature v4 to use with AWS IOT MQTT

I created this because I couldn't find a library to easily generate signed urls that you can use with amazon's MQTT for IOT in python. All the libraries I could find would be to generate headers for HTTP requests and it wouldn't work with wss for MQTT.

Inspired by:

Installing

pip install aws-signv4-mqtt

How to use use

There are two interfaces:

aws_signv4_mqtt.generate_signv4_mqtt( iot_host, iot_region, access_key, secret_key, session_token = None)

Basic interface to created the signed url.

aws_signv4_mqtt.generate_signv4_mqtt_boto( iot_host, iot_region)

Gets the credentials from your environment or iam role internally using boto3.

Examples

import aws_signv4_mqtt
print(aws_signv4_mqtt.generate_signv4_mqtt('<your_iot>.iot.us-east-1.amazonaws.com', 'us-east-1', '<aws_access_key>', '<aws_secret>'))

Prints something like:

wss://<your_iot>.iot.us-east-1.amazonaws.com/mqtt?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=%3Caws_access_key%3E%2F20190216%2Fus-east-1%2Fiotdevicegateway%2Faws4_request&X-Amz-Date=20190216T115653Z&X-Amz-SignedHeaders=host&X-Amz-Signature=92bfc2b5a77489c5786a820044bf6c8ccb3c2f9b40c1d6a5f016b4d9c8662a5e

Testing your url

After you generate your url using AWS credentials with sufficient AWS IOT permissions, you can test it with any MQTT library.

For instance, you could execute the javascript code below:

var mqtt = require('mqtt')
url = '<your_signed_url>'
port = 443
topic = '<your_topic>'
i = 0

var client  = mqtt.connect(url,
    {
        connectTimeout:5*1000,
        port: port,
    })

client.on('connect', function () {
  client.subscribe(topic, function (err) {
    if (!err) {
      client.publish(topic, 'Hello mqtt')
    }
  })
})

client.on('message', function (topic, message) {
  console.log(message.toString())
  i = i+1
  client.publish(topic, 'Hello mqtt '+String(i))
})

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aws_signv4_mqtt-0.2.0.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

aws_signv4_mqtt-0.2.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file aws_signv4_mqtt-0.2.0.tar.gz.

File metadata

  • Download URL: aws_signv4_mqtt-0.2.0.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for aws_signv4_mqtt-0.2.0.tar.gz
Algorithm Hash digest
SHA256 59cb22ea836d3e72b0cd3dae0ef337ac29af3e9e498aed13a55e711c4c250413
MD5 5ba58617a8febe93382e81468d65d781
BLAKE2b-256 d057ba3110490b3af46be9cd6f165e84898c16a411f1aa5c0d81d2b701ada9f2

See more details on using hashes here.

File details

Details for the file aws_signv4_mqtt-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: aws_signv4_mqtt-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.3

File hashes

Hashes for aws_signv4_mqtt-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4fb69ba044a1712b4c8e0464c34efb27b186d545c0c4aaf5907b97e30eebcffb
MD5 a0996ae02ddcef27e347a30758cb5caa
BLAKE2b-256 6b51981e08f75809fef6765eb56df5b567fb0af87862f53d96fdecdfe68486ab

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page