amplify-js: React Native: "AMQJS0007E Socket error:undefined."

Describe the bug I am using AWS Amplify to connect to AWS IoT Core and getting error “AMQJS0007E Socket error:undefined.” I have integrated aws amplify in expo app.

Sample code

import React from "react";
import { StyleSheet, Text, View } from "react-native";
import Amplify, { PubSub, Auth } from "aws-amplify";
import { AWSIoTProvider } from "@aws-amplify/pubsub/lib/Providers";

Amplify.configure({
  Auth: {
    identityPoolId: "ap-south-1:xx-xx-xx-xx-xx",
    region: "AP_SOUTH_1",
    userPoolId: "ap-south-1_xx",
    userPoolWebClientId: "xxx"
  }
});
Amplify.addPluggable(
  new AWSIoTProvider({
    aws_pubsub_region: "ap-south-1",
    aws_pubsub_endpoint: "wss://xx.iot.ap-south-1.amazonaws.com/mqtt"
  })
);
class App extends React.Component {
  async componentDidMount() {
    Auth.configure();
    const sub1 = PubSub.subscribe("$aws/things/xxx/shadow/update").subscribe({
      next: data => console.log("Message received", data),
      error: error => console.error(error),
      close: () => console.log("Done")
    });
  }
  render() {
    return (
      <View style={styles.container}>
        <Text>Open up App.js to start working on your app!</Text>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: "#fff",
    alignItems: "center",
    justifyContent: "center"
  }
});

export default App;

Error details

  • errorCode: 7
  • errorMessage: “AMQJS0007E Socket error:undefined.”
  • invocationContext: undefined

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 17 (2 by maintainers)

Most upvoted comments

Can you try removing Auth.configure();.

Amplify.configure({
  Auth: {
    identityPoolId: "ap-south-1:xx-xx-xx-xx-xx",
    region: "AP_SOUTH_1",
    userPoolId: "ap-south-1_xx",
    userPoolWebClientId: "xxx"
  }
});

The above configure should handle Auth configuration.

If this still does not work, could you try moving

Amplify.addPluggable(
  new AWSIoTProvider({
    aws_pubsub_region: "ap-south-1",
    aws_pubsub_endpoint: "wss://xx.iot.ap-south-1.amazonaws.com/mqtt"
  })
);

above Amplify.configure({...})

I had the same problem, but I solved mine by using ‘iot:Data-ATS’ endpoint type instead of ‘iot:Data’. Basically, use ‘wss://xx-ats.iot.ap-south-1.amazonaws.com/mqtt’ (notice the added ‘-ats’) for your aws_pubsub_endpoint.

@naseemrafique https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Iot.html#attachPrincipalPolicy-property With aws SDK, by calling this method for each user that logins, server-side.

We (@cayce) are running into the same issue. The AWS IoT CloudWatch logs are showing this: { “timestamp”: “2019-08-05 14:00:01.688”, “logLevel”: “ERROR”, “traceId”: “4f37a2d5-0d10-6ad6-239c-91f247358152”, “accountId”: “771585994482”, “status”: “Failure”, “eventType”: “Connect”, “protocol”: “MQTT”, “clientId”: “856e9f8b-cac6-42c4-988d-d837339e6a4e”, “principalId”: “AROA3HJQ353ZD67RJBGBT:CognitoIdentityCredentials”, “sourceIp”: “62.219.214.242”, “sourcePort”: 25160, “reason”: “AUTHORIZATION_FAILURE”, “details”: “Authorization Failure” }

We’ve also done the following: We coded a small NodeJS app that uses aws-iot-device-sdk:

var awsIot = require('aws-iot-device-sdk');
let device = awsIot.device({
    clientId: '<MQTT client Id from Amplify debug log>',
    host: '<endpoint>.iot.us-east-1.amazonaws.com',
    protocol: 'wss',
    accessKeyId: '< The access key Id provided by Cognito from Auth.currentCredentials()>',
    secretKey: '<The secret key provided by Cognito from Auth.currentCredentials()>',
    sessionToken: '<The session token provided by Cognito from Auth.currentCredentials()>'
});
device.on('connect', () => {
    console.log('connected');
});
device.on('error', (e) => {
   console.log(e);
});
device.on('close', () => {
    console.log('closed');
});
device.on('reconnect', () => {
   console.log('reconnected');
});
device.on('offline', () => {
    console.log('offline');
})

We got the following output: offline closed reconnected closed reconnected closed reconnected closed reconnected closed reconnected closed reconnected closed reconnected closed reconnected closed

And saw the same error in the CloudWatch logs.

If we ran our small test app with my Admin credentials -> it was connected and publishing.