简体   繁体   English

如何验证消息是否在 AWS SNS 中传递?

[英]How to verify message is delivered or not in AWS SNS?

Here is my lambda function.这是我的 lambda 函数。 only return message-id and request-id.只返回消息 ID 和请求 ID。 but how to verify the message is delivered or not?但是如何验证消息是否已传递?

        const AWS = require('aws-sdk');
           AWS.config.update({
                accessKeyId: 'xxxx',
                secretAccessKey: 'xxxx',
                region: 'xxxx'

            });
            const mobile = 'xxxxxxx';
            const sns = new AWS.SNS();
        const confirmUpload =  (callback) => {
          sns.publish({
            Message: 'Test From Admin side',
                Subject: 'Admin',
                MessageStructure: 'string',
                PhoneNumber: mobile
          }, (err, result) => {
            if (err) callback(false, err);
            else callback(true, result);

          });
        };
        exports.handler =  (event,context, callback) => {
            confirmUpload((st, data) =>{
                if(st){
                    let record = {
                        "data": JSON.stringify(data),
                        "event": event,
                        "context": context
                    };
                    callback(null, (record));
                } else{
                    callback(data, "not send");
                }
            });
        };

And here is the response when running the lambda function这是运行 lambda 函数时的响应

        "{\"ResponseMetadata\":{\"RequestId\":\"e8a07b26-d793-58e1-a529-2d7ac17aca9x\"},\"MessageId\":\"b8ecbcac-9f83-5bca-a9eb-eaf0896a69b\"}",

If you enable the delivery status feature on your topics you can use the message ID field in order to track the delivery status of the messages you have published.如果您对您的主题启用传递状态功能,您可以使用消息 ID 字段来跟踪您发布的消息的传递状态。

After you configure the message delivery status attributes, log entries will be sent to CloudWatch Logs for messages sent to a topic subscribed to an Amazon SNS endpoint.在您配置消息传输状态属性后,对于发送到订阅了 Amazon SNS 终端节点的主题的消息,日志条目将发送到 CloudWatch Logs。 Logging message delivery status helps provide better operational insight, such as the following:记录消息传递状态有助于提供更好的操作洞察力,例如:

  • Knowing whether a message was delivered to the Amazon SNS endpoint.了解消息是否已传送到 Amazon SNS 终端节点。

  • Identifying the response sent from the Amazon SNS endpoint to Amazon SNS.识别从 Amazon SNS 终端节点发送到 Amazon SNS 的响应。

  • Determining the message dwell time (the time between the publish timestamp and just before handing off to an Amazon SNS endpoint).确定消息停留时间(发布时间戳和移交给 Amazon SNS 终端节点之前的时间)。

Configuring Delivery Status Logging Using the AWS Management Console 使用 AWS 管理控制台配置交付状态日志记录

You can look into this article to look for delivery status using message ID您可以查看本文以使用消息 ID 查找传递状态

using-the-delivery-status-feature-of-amazon-sns using-the-delivery-status-feature-of-amazon-sns

Btw I will not suggest to check in the same lambda but to configure cloud watch logs and filter failure topic only.顺便说一句,我不会建议签入相同的 lambda,而是仅配置云监视日志和过滤失败主题。 Here will be flow这里会有流量

  1. Enable delivery status logs for the topic为主题启用传递状态日志
  2. Configure filter on Cloud watch for the failed topic在 Cloud watch 上为失败的主题配置过滤器
  3. Trigger lambda when delivery status if failed如果失败,则在交付状态时触发 lambda
  4. Process the failed SNS topic in lambda.在 lambda 中处理失败的 SNS 主题。

You may also like SLA for SNS by AWS.您可能还喜欢 AWS 的 SNS SLA

You can enable SNS dead-letter queues to catch messages that can't be delivered to subscribers:您可以启用 SNS 死信队列来捕获无法传递给订阅者的消息:

https://aws.amazon.com/blogs/compute/designing-durable-serverless-apps-with-dlqs-for-amazon-sns-amazon-sqs-aws-lambda/ https://aws.amazon.com/blogs/compute/designing-durable-serverless-apps-with-dlqs-for-amazon-sns-amazon-sqs-aws-lambda/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM