0

I am trying to use AWS IoT Device SDK JS 2 with a simple ReactJS application.
The application is targeted to run in a browser.
I have all the required certificates and credentials with me to configure the application.

I have below sample code to create MQTT connection:

import { iot } from 'aws-iot-device-sdk-v2';
import React, { useState } from 'react';

function App() {
    try {
      const config = iot.AwsIotMqttConnectionConfigBuilder.newDirectMqttBuilderWithMtlsFromPath(
        'endpoint',
        'device.pem.crt',
        'private.pem.key'
      );

    .. Rest of the code ..

When I build and run this code I am getting below error in browser console.

TypeError: aws_iot_device_sdk_v2__WEBPACK_IMPORTED_MODULE_0__.iot.AwsIotMqttConnectionConfigBuilder.new_mtls_builder_from_path is not a function

Is there any issue the way I am trying to access the APIs from iot or webpack is causing this issue?

1 Answer 1

0

new_mtls_builder_from_path is not supported in browsers. You can take a look at the API docs. Node version describes new_mtls_builder_from_path. The browser version doesn't have it.

I suggest to take a look at the react sample provided in AWS IoT Device SDK JS 2 repo (please, stick to MQTT5 version if possible).

Also, there is an old issue, where someone tried to use newDirectMqttBuilderWithMtlsFromPath in browser and had the same issue. Maybe comments there will give you some insights.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.