Amazon SNS:如何获取确认订阅的令牌

Amazon SNS: how to get token for confirm subscription

以下创建一个等待确认的订阅。

aws_client.subscribe(TopicArn=topic_arn, Protocol=protocol, Endpoint=endpoint)

对此的响应类似于:

{'ResponseMetadata': {'HTTPHeaders': {'content-length': '298',
   'content-type': 'text/xml',
   'date': 'Fri, 13 Oct 2017 10:15:47 GMT',
   'x-amzn-requestid': '7a0a40fb-ab72-5584-94f0-12a13fe11das'},
  'HTTPStatusCode': 200,
  'RequestId': '7a0a40fb-ab72-5584-94f0-12a13fe11das',
  'RetryAttempts': 0},
 u'SubscriptionArn': 'pending confirmation'}

以上响应未发送任何令牌。 如何获取可以传递给 confirm_subscription 的令牌,如 here

所述

似乎无法从 subscribe 命令本身的响应中获得令牌。相反,作为 mentioned in the Boto 3 documentation,令牌是

"...sent to the endpoint by an earlier Subscribe action." (emphasis mine)

AWS CLI Command Reference 陈述了同样的事情,但也许更清楚一点:

"Short-lived token sent to an endpoint during the subscribe action." (emphasis mine)

换句话说,对于电子邮件端点,令牌在电子邮件本身中。如果您查看 "Confirm subscription" Link 的 URL 就可以看到它。

例如,它看起来像 https://sns.us-east-1.amazonaws.com/confirmation.html?TopicArn=arn:aws:sns:us-east-1:123456789:my-aws-topic&Token=abc123&Endpoint=address@email.com

在此示例中,您可以看到令牌将是 abc123