enesefuu
enesefuu

Reputation: 409

Error "URL.hostname is not implemented", AWS SNS in React Native Android

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

import { 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

Upvotes: 6

Views: 7213

Answers (1)

enesefuu
enesefuu

Reputation: 409

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.

Upvotes: 25

Related Questions