To use aws-iot-device-sdk in React-Native, you need to follow Viotti's suggestion above (https://github.com/aws/aws-iot-device-sdk-js/issues/86#issuecomment-371159865) but with some new additions including adding 'url' and 'events' to the nodeify step. The problem we all face is that React-Native uses JavaScriptCore which is not the same as NodeJS and it is not the same as any specific browser JS engine either, though it is used in Safari. In order to use aws-sdk and aws-iot-device-sdk you need to include libraries that replace several important NodeJS libraries. rn-nodeify is an NPM package that makes this somewhat easy to do. The key step in the walk through on GitHub is here:
npx rn-nodeify --install "fs,util,path,tls,stream,buffer,global,process,events,url" --hack
This will install libraries that replace what is missing when not in nodejs, and create a shim.js file that you need to copy to your project's files and import. Within that Shim file you'll need to also make further modifications. buffer
should already be installed, but the require or import statement must read `import { Buffer } from 'buffer/'; with the trailing slash, to separate it from the nodejs version for confused transpilers.
Other libraries I have needed for this include react-native-crypto, which can be used to replace NodeJS's crypto. Edit rn-nodeify's shim file to allow crypto. In order to make use of WSS on AWS in React-Native I've also used react-native-wss which helps handle certs in WSS.