AWS SNS Endpoint getting disabled on its own

2019-04-11 12:45发布

问题:

I have setup my Android and iOS app to be able to receive notifications via SNS. The setup is working fine and the device do receive the notifications. But later on, the notification starts to fail.

I have already enabled logging for both success and failure scenarios. And according to the logs, I keep receiving errors of the form: "Endpoint is disabled:arn:aws:sns:myRegion:myAccount:endpoint/GCM/myApp/myDeviceEndpointHash"

I know the error means that the endpoint is disabled. Also, I am aware of the methods of re-enabling the endpoint via console and API.

My question is why this keeps on happening. This is happening with 99% of the device I am pushing the notifications to. Thanks in advance.

回答1:

After a long conversation with the AWS support team, there were a couple of things that surfaced.

  1. GCM and APNS can disable your device's endpoint, based on some cleanup policy. In other words, the devices are subjected to change in their endpoints and is not in control of AWS.
  2. When GCM disables your device endpoint, then it create a mapping between the new endpoint and the old endpoint. Using this mapping, it is still able to serve notifications via the old endpoint. But, this mapping is there for a short while only. Once, this mapping is gone, the notifications start to fail. Also, while the mapping is there, the GCM provides a warning message to SNS, that the endpoint will soon be disabled and also provides the new endpoint, but it only gets logged.

Now, what to do? The solution has two parts:

  1. Whenever your app starts, you create a new endpoint for it, carry out the entire SNS registration process for this device. This causes the SNS repository to be updated with the latest device endpoint provided by GCM.
  2. Let's say the user has not started the app for a very long duration. Then, you can place a Lambda on the SNS logs, using this Lambda you can determine when the endpoint is about to be disabled. For this event, you can push a silent notification to the device and then your device must re-register itself on SNS silently.

This second step has a lot of work involved, both on server and device side. In the end, we decided not to implement it since it does not happen for majority of users and the work involved could not be justified.