【问题标题】:SNS SDK for NodeJS won't create FIFO topicNodeJS 的 SNS SDK 不会创建 FIFO 主题
【发布时间】:2021-09-13 12:54:37
【问题描述】:

当我使用 sns.createTopic(如下面的代码)创建主题时,它不会接受布尔值并说 'InvalidParameterType: Expected params.Attributes['FifoTopic'] to be a string',即使文档说要提供布尔值,当我为它提供一个'true'字符串时,它仍然没有将主题类型设置为FIFO,有人知道为什么吗?

代码如下:

const TOPIC = {
    Name: 'test.fifo',
    Attributes: {
        FifoTopic: true,
        ContentBasedDeduplication: true
    },
    Tags: [{
        Key: 'test-key',
        Value: 'test-value'
    }]
};
sns.createTopic(TOPIC).promise().then(console.log);

【问题讨论】:

    标签: node.js amazon-web-services aws-sdk amazon-sns aws-sdk-js


    【解决方案1】:
    • 使用aws-sdkV2
    • 我将 FifoTopic 和 ContentBasedDeduplication 作为字符串发送。

    下面的代码对我来说很好用

    const TOPIC = {
        Name: 'test.fifo',
        Attributes: {
            FifoTopic: "true",
            ContentBasedDeduplication: "true"
        },
        Tags: [{
            Key: 'test-key',
            Value: 'test-value'
        }]
    };
    let sns = new AWS.SNS();
    let response3 =await sns.createTopic(TOPIC).promise();
    console.log(response3);
    

    注意:确保您的 lambda 具有正确的权限。

    • 在执行 getTopicAttributes 时,您将获得 FifoTopic 和 ContentBasedDeduplication 等属性。

      让 respo = await sns.getTopicAttributes({ TopicArn:"arn:aws:sns:us-east-1:XXXXXXX:test.fifo"} ).promise();

    请找到截图

    【讨论】:

    • 当您使用 getTopicAttributes 时,您是否在“Attributes”键中获得“FifoTopic”和“ContentBasedDeduplication”值?因为我没有得到它们(即使文档说它们应该被退回),这就是为什么我认为该主题不是 FIFO(我在本地使用 SNS 进行开发和 localstack docker 映像,因此我没有控制台来检查主题类型)
    • 您好,执行 sns.getTopicAttributes 时返回 FIFO 属性。请找到上面的答案。
    猜你喜欢
    • 2021-05-01
    • 2021-09-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-03
    • 1970-01-01
    • 1970-01-01
    • 2020-07-23
    相关资源
    最近更新 更多