aws-amplify / aws-amplify/docs
[Feedback]Not been able to use PubSub with React Native
- Dominant language
- MDX
- Stars
- 506
- Forks
- 1.1k
- Avg merge
- 3h 14m
- Merged PRs (30d)
- 1
Description
**Page**: [`/lib/pubsub/getting-started/q/platform/[platform]`](https://docs.amplify.aws/lib/pubsub/getting-started/q/platform/react-native)
**Feedback**:
I have followed all the instructions as mentioned clearly in the documentation but still could not perform any PubSub operation.
**My Tech Stack:**
React Native
AWS IoTCore
Steps I followed:
1. Created the React Native project
2. Installed all the mentioned libraries via npm
3. Imported the modules and configured as mentioned in the documentation
4. Create a new IoT policy with "*" permission.
5. Attached the policy with the Cognito Identity ID, (I fetched the ID using cognito-idp API call via cURL)
6. Navigated to CloudFormation and attached both AWSIoTDataAccess and AWSIoTConfigAccess policies
Even after following all the steps in this order could not able to perform any subscription operation

PS: These are the logs that Expo console keeps showing.
There is no error being thrown in any of the subscribe or publish, I have implemented the operations in try/catch blocks to see the errors, but still none are shown.
```js
import { StatusBar } from "expo-status-bar";
import { Pressable, StyleSheet, Text, View } from "react-native";
import { Amplify, PubSub, Auth } from "aws-amplify";
import { AWSIoTProvider } from "@aws-amplify/pubsub";
import awsExports from "./aws-exports";
import { payload as mock } from "./mock";
import { useEffect } from "react";
Amplify.configure(awsExports);
Amplify.addPluggable(
new AWSIoTProvider({
aws_pubsub_endpoint:
"wss://a2qjty4wsdd1fv-ats.iot.ap-south-1.amazonaws.com",
aws_pubsub_region: "ap-south-1",
clientId: "app-client",
})
);
async function testPublish() {
console.log("testing");
// console.log(mock)
try {
await PubSub.publish("$aws/things/SmartHomeApp/shadow/get");
console.log("worked");
} catch (error) {
console.log("Error in publish");
console.error(error);
}
}
export default function App() {
// const netInfo = useNetInfo();
useEffect(() => {
PubSub.subscribe([
"$aws/things/SmartHomeApp/shadow/get/accepted",
"$aws/things/SmartHomeApp/shadow/get/rejected",
]).subscribe({
next: (data) => {
console.log("Message received", data);
},
error: (error) => {
console.error("error", error);
},
complete: () => console.log("Done"),
start: () => {
console.log("Started");
},
});
}, []);
return (
testPublish()}>
Test
Open up App.js to start working on your app!
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: "#fff",
alignItems: "center",
justifyContent: "center",
},
button: {
backgroundColor: "#000000",
padding: 10,
borderRadius: 5,
},
text: {
color: "#fff",
},
});
```
Contributor guide
Assessment
This issue has not been assessed yet.