React Native Android 中的 AWS SNS 错误“URL.hostname 未实现”

ene*_*fuu 6 react-native aws-sdk-js

在 React Native 中使用适用于 JavaScript v3 的 AWS 开发工具包中的 SNS 服务

当我尝试创建端点(或通过 AWS 执行任何命令)时,出现此错误URL.hostname is not implemented

  • 我尝试了许多其他命令;同样的错误
  • 我所做的唯一会产生不同错误的事情是,如果我region在创建客户端时从参数中删除。Region is missing然后它在同一个地方出错。但值得注意的是,如果我只是asdf123为区域传递无意义的 (),它会产生相同的 URL.hostname 错误
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 
})

Run Code Online (Sandbox Code Playgroud)

这意味着我应该在此错误中包含更多数据,但此错误中唯一的内容就是消息。https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-sns/index.html#troubleshooting

似乎这甚至不是 AWS 错误...但我不知道如何进一步排除故障。

任何有关如何确定其来源的建议将非常感激。谢谢大家

ene*_*fuu 23

发现一些帖子建议这样做以解决类似的错误:react-native-url-polyfill

添加后,我开始收到此错误: [Error: crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported]

为了解决这个问题我添加了react-native-get-random-values

...并且它有效。我不确定我理解为什么,或者根本原因是什么,这似乎是一个有点混乱的解决方法。但它确实有效。

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 
Run Code Online (Sandbox Code Playgroud)

如果有人可以阐明这里发生的事情,毫无疑问有更好的方法。

  • 有同样的问题。发现如果使用AWS的模块化接口,需要这两个包。这在他们的入门指南中记录了 https://github.com/aws/aws-sdk-js-v3#getting-started (3认同)