Using Python to Communicate with AWS IoT Core

   Go back to the Task List

  « 2. Register the Device    4. Develop Code to Exchange Message »

3. Configure Cloud9 Environment

AWS Cloud9 is a cloud-based integrated development environment (IDE) from Amazon Web Services. You will configure Cloud9 development environment to work as the device running Python code. The environment has to be configured with AWS IoT Device SDK for Python in order to develop such code. Let’s do it.

  1. Goto the AWS Cloud9 console and click on the Create environment button.

    Cloud9

  2. On the next screen, enter dojoenvironment as the name and click on the Next step button.

    Cloud9

  3. On the next screen, select Environment type as Create a new instance for environment (EC2). Select Instance type as t3.small (2 GiB RAM + 2 vCPU). Select Ubuntu Server 18.04 LTS for the Platform. The development environment will have Ubuntu as the operating system. Keep rest of the fields with the default values and click on the Next step button.

    Cloud9

  4. On the next screen, click on the Create environment button.

  5. It will take couple of minutes to create the environment. Wait for the environment to be ready. Once it is ready, you can see bash console window in the bottom part of the screen. It provides console base access to the development machine.

  6. Python3 is already installed in the environment. You can check it by running the command bellow in the console.

     python3 --version
    

    `

    Cloud9

  7. You will now configure the environment for AWS IoT Device SDK for Python. Run the following command to clone the SDK from the github.

     git clone https://github.com/aws/aws-iot-device-sdk-python.git
    

    `

    Cloud9

  8. Run the following commands one by one to move into aws-iot-device-sdk-python folder and install the SDK.

     cd aws-iot-device-sdk-python
     sudo python setup.py install
    

    ` Cloud9

  9. Use cd .. command to go back to the root directory of the environment.

    Cloud9

  10. The SDK is configured. Since the device uses x509 certificates for the authentication in AWS IoT core. You will upload the device certificate files to the Cloud9 environment. When you write python code, you will use the certificates for the authentication. You downloaded the certificate files in the previous tasks. Click on the Upload Local Files option under the File menu.

    Cloud9

  11. On the next screen, goto the location where you downloaded the files (your file names would be different). Select RootCA certificate, private key and X509 certificate and click on the Open button.

    Cloud9

  12. The files get loaded to the root folder of the AWS Cloud9 environment.

    Cloud9

  13. The Cloud9 environment is ready for the Python programming with AWS Device SDK. In the next task, you write code to send and receive messages with the IoT core.