将自定义 SNS 通知仅发送到选定的端点 - 使用 lambda

Sending custom SNS notifications to only selected endpoints- using lambda

假设我有 100 人订阅了一个名为 :"remeinde_me_my_appointment" 的主题,并且我有 lambda 函数,它为我提供了一个包含 5 个人及其端点的列表,明天应该提醒他们他们的约会。

现在我的问题是,lambda 和 SNS 之间的通信应该如何进行?

我只想向 5 个注册接收通知的人发送 5 条消息,而且我神奇地得到了他们所有的端点。

我又把他们送回主题了吗?!如果我感到困惑,我该怎么办?看来我已经定义了自己的主题和订阅,但下一步是什么?

这不是订阅 Amazon SNS 主题的好用例。

当消息发送到 SNS 主题时,所有收件人都会收到消息。您还可以使用 Amazon SNS Message Filtering 根据消息属性限制接收消息的订阅者。

但是,根据您的用例,这不是发送消息的好方法。通过向每个人发送单独的消息 以及有关他们约会的自定义信息,您的用例可能会得到更好的处理,例如:

Dear Joe, this is a reminder of your appointment with Dr Smith at 10am tomorrow.

因此,不要向主题发送消息,而是使用带有端点 ARN 的 Amazon SNS publish() 命令:

sns.publish(TargetArn=user_endpoint_arn, Message=msg)

To use the Publish action for sending a message to a mobile endpoint, such as an app on a Kindle device or mobile phone, you must specify the EndpointArn for the TargetArn parameter. The EndpointArn is returned when making a call with the CreatePlatformEndpoint action.

这适用于向移动应用程序发送消息。

如果您只是发送短信,那么您可以直接发布到手机号码:

sns.publish(PhoneNumber='+16025551234', Message=msg)