Skip to content

Instantly share code, notes, and snippets.

@rnagarajanmca
Last active May 2, 2019 01:40
Show Gist options
  • Select an option

  • Save rnagarajanmca/7baeb77fd4abc20700ed0cdb4c889b28 to your computer and use it in GitHub Desktop.

Select an option

Save rnagarajanmca/7baeb77fd4abc20700ed0cdb4c889b28 to your computer and use it in GitHub Desktop.

Preparing RPi to connect with AWS IoT

Follow the steps to setup RPi as AWS IoT thing Do a Raspbian update by using following command

>sudo apt-get update
>sudo apt-get upgrade

Minimum Requirements

Python 2.7+ or Python 3.3+

OpenSSL version 1.0.1+ compiled with the Python executable for X.509 certificate-based mutual authentication

To check your version of OpenSSL, use the following command in a Python interpreter:

>>> import ssl
>>> ssl.OPENSSL_VERSION

Install AWS SDK from pip

pip install AWSIoTPythonSDK

Use the SDK

Credentials

  • AWS IoT supports four types of identity principals for authentication:

    • X.509 certificates
    • IAM users, groups, and roles
    • Amazon Cognito identities
    • Federated identities

The SDK supports two types of credentials that correspond to the two connection types:

  • X.509 certificate

For the certificate-based mutual authentication connection type. Download the AWS IoT root CA. Use the AWS IoT console to create and download the certificate and private key. You must specify the location of these files when you initialize the client.

  • IAM credentials

For the Websocket with Signature Version 4 authentication type. You will need IAM credentials: an access key ID, a secret access key, and an optional session token. You must also download the AWS IoT root CA. You can specify the IAM credentails by:

  • Passing method parameters
The SDK will first call the following method to check if there is any input for a custom IAM credentials configuration:
# AWS IoT MQTT Client
AWSIoTPythonSDK.MQTTLib.AWSIoTMQTTClient.configureIAMCredentials(obtainedAccessKeyID, obtainedSecretAccessKey, obtainedSessionToken)
# AWS IoT MQTT Shadow Client
AWSIoTPythonSDK.MQTTLib.AWSIoTMQTTShadowClient.configureIAMCredentials(obtainedAccessKeyID, obtainedSecretAccessKey, obtainedSessionToken)

We can use AWS CLI to share the credentials. Follow this links to To Configure AWS CLI

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment