Using SNS service from the AWS SDK for JavaScript v3 in React Native
When I try to create an endpoint (or execute really any command through AWS) I'm getting this error URL.hostname is not implemented
region
from the params when creating the client. Then it errors Region is missing
in the same place. But worth noting, if I just pass nonsense (asdf123
) for region it yields this same URL.hostname errorimport { CognitoIdentityClient } from "@aws-sdk/client-cognito-identity";
import { fromCognitoIdentityPool } from "@aws-sdk/credential-provider-cognito-identity";
import { SNSClient, CreatePlatformEndpointCommand } from "@aws-sdk/client-sns";
const region = 'us-west-2'
const sns = new SNSClient({
region: region,
credentials: fromCognitoIdentityPool({
client: new CognitoIdentityClient({ region }),
identityPoolId: identityPoolId,
}) /// doesn't matter whether I pass credentials or not, same result
});
const params = {
PlatformApplicationArn: platformApplicationArn,
Token: token
}
const command = new CreatePlatformEndpointCommand(params);
const res = await sns.send(command)
.catch((err) => {
console.log(err) //// this is the "[Error: not implemented]"
throw err
})
This is saying I should have more data in this error but the only thing in this error is the message. https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sns/index.html#troubleshooting
Seems like this isn't even an AWS error...but I have no idea how to troubleshoot further.
Any suggestions on how to identify where this is coming from would be SUPER APPRECIATED. Thanks all
Found some posts which suggested this for similar errors: react-native-url-polyfill
Once that was added I started getting this error instead:
[Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported]
To solve this I added react-native-get-random-values
... and it works. I'm not sure I understand why, or what the root cause is, and this seems like kinda a messy workaround. But it does work.
import 'react-native-url-polyfill/auto';
import 'react-native-get-random-values';
import { v4 as uuidv4 } from 'uuid';
//at the top of the file where I'm handling AWS SNS
If anyone out there can shed light on what's going on here, no doubt there's a better way.