Search code examples
amazon-web-servicesreact-nativereact-native-iosaws-iot

How to implement AWS IoT(device) in React-Native?


I am trying to Implement AWS-IoT(device) using React-Native.

I have used the packages,

1) aws-iot-device-sdk-js

2) react-native-aws-iot-device-shadows

and got a lot of errors while using the package. I could debug few, but did not get expected results.

I am Implementing AWS-IoT for Chatting application.

I am successfully creating an IoT session using REST APIs and get these as responses iotEndpoint, region, accessKey, secretKey, sessionToken. But using these credentials I am unable to Connect using the above packages.


Solution

  • I figured this out,

    Step 1: Install aws-iot npm package npm install --save aws-sdk aws-iot-device-sdk

    Step 2: Install the nodeify package npm install --save-dev rn-nodeify

    Step 3: Run this command to install series of packages specified

    npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process" --hack
    

    "Please wait until the all the packages are installed"

    Step 4: Goto package.json -> in scripts section add,

    "postinstall": "rn-nodeify --install fs,util,path,tls,stream,buffer,global,process --hack"
    

    Step 5 : Install the asyncstorage-down package npm install --save asyncstorage-down

    Step 6: rn-nodeify will auto-generate a file shim.js in the root part of your react-native project. Just import it in index.js file like this import './shim'

    Finally, you are ready to use your aws-iot package !!!

    It is advisable to generate the iot-session keys as specified in the question above using REST API's in the backend.