【问题标题】:How to extract the token from SNS Subscribe and use it in confirmSubscription method?如何从 SNS 订阅中提取令牌并在确认订阅方法中使用它?
【发布时间】:2019-03-22 02:23:33
【问题描述】:

用例

我想订阅 SNS 主题的电子邮件,我需要以编程方式确认,而不是手动点击确认链接。

我做了什么

这通常是为了确认我正在使用 SNS confirmSubscription 方法,该方法将 token 作为参数。我可以通过将协议传递为email-json 来调用SNS subscribe 方法来获得令牌。为此,我在端点收到了以下订阅消息。

{
  "Type" : "SubscriptionConfirmation",
  "MessageId" : "xxx-9160-49a3-960f-xx",
  "Token" : "2336412f37fb687adfaf",
  "TopicArn" : "arn:aws:sns:ap-south-1:xx-xx",
  "Message" : "You have chosen to subscribe to the topic arn:aws:sns:ap-south-1:xx-xx.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
  "SubscribeURL" : "https://sns.ap-south-1.amazonaws.com/?Action=xx&TopicArn=arn:aws:sns:ap-south-1:477530015769:xx-xx&Token=2336412f37fb6872",
  "Timestamp" : "2019-03-21T08:34:26.597Z",
  "SignatureVersion" : "1",
  "Signature" : "bIwq8Q92Yvrn8bBrIDQJ2chc5y/5IPAZPPR4roZ6WfK7kaE0QTbJpqAmHMH0sHL4aoyTrapLwX4e6HaEd6nGny8EAWj5wA2JvFCrO9BFQu",
  "SigningCertURL" : "https://sns.ap-south-1.amazonaws.com/SimpleNotificationService-xx.pem"
}

我想要什么

如何从上述 json 中提取 token 值。这是我用来以编程方式确认 sns 订阅者的以下 lambda。

const AWS = require('aws-sdk');
var sns = new AWS.SNS();
var snsconfirm= {
  Token: 'xx', /* required */ -->How can i able to retrieve the token value from the endpoint json.
  TopicArn: 'arn:aws:sns:ap-south-1:xxx:xx-xxx', /* required */
  AuthenticateOnUnsubscribe: 'true'
};
var snsparams = {
  Protocol: 'email-json', /* required */
  TopicArn: 'arn:aws:sns:ap-south-1:xx:xx-xx', /* required */
  Endpoint: 'abc@xyz.com'
};
exports.handler = async (event) => {
    // TODO implement
try {
  const snsrespone = await sns.subscribe(snsparams).promise();
  const confirmsub = await sns.confirmSubscription(snsconfirm).promise();
  } catch (err) {
    console.log(err.message);
    throw err;
  }
};

任何帮助表示赞赏 谢谢

【问题讨论】:

    标签: amazon-web-services amazon-sns


    【解决方案1】:

    如果您有令牌,您只能以编程方式确认订阅,正如您已经发现的那样。这很可能确保您不会不情愿地订阅某人。

    假设您可以访问端点,您唯一的选择是设置某种过滤器,以触发可以订阅回复的 Lambda。可能通过在您的电子邮件中设置电子邮件转发规则以转发到 SES 电子邮件,进而触发确认订阅的 Lambda。

    【讨论】:

      猜你喜欢
      • 2018-03-25
      • 1970-01-01
      • 1970-01-01
      • 2012-09-30
      • 2016-07-23
      • 2017-12-22
      • 2015-06-10
      • 2023-03-10
      • 1970-01-01
      相关资源
      最近更新 更多