Why is my push notification endpoint not active?

4 minute read
0

Whenever I send push notifications to Amazon SNS endpoints (Android or iOS devices) the endpoints get deactivated.

Short description

Amazon Simple Notification Service (Amazon SNS) can send push notifications messages to mobile devices. These messages appear in mobile applications as badge updates, sound alerts, or message alerts.

When you add a device token as an endpoint to the Platform application, it sets that endpoint's Enabled value to True. When SNS publishes a notification, it contacts the push notification service, such as Apple Push Notification Service (APNs) or Firebase Cloud Messaging (FCM). The push notification service then sends the message to the mobile device.

If the push notification service can't communicate with the mobile device, it sends feedback to SNS about the message delivery failure. SNS marks the endpoint as deactivated (that is, the attribute Enabled is set to False) when the notification service indicates that the endpoint isn't valid. After the endpoint is deactivated, SNS rejects subsequent publishing calls to the endpoint. For more information, see GetEndpointAttributes.

Resolution

Endpoints get deactivated when push notifications are sent to endpoints that don't have a valid device token associated with them.

Reasons why an endpoint gets deactivated

Here are some common reasons why an endpoint might be deactivated:

  • The end user uninstalled the application from the device. If you publish to the corresponding SNS endpoint, the endpoint is deactivated.
  • The end user reinstalled the application. The device now gets a new token and then renders the old token as not valid.
  • The end user upgraded the device's operating system. This makes the existing token incompatible with the upgraded software. Your application needs to request a new token.
  • The end user upgraded the application from the Apple's App Store or from Google Play. The end user hasn't yet launched the application so that the application can update its token.
  • For APNs, the push Secure Socket Layer (SSL) certificate isn't valid or doesn't match the environment (Production or Sandbox).
  • The end user restored the device from a backup.
  • The token isn't valid and doesn't belong to an active installation of the application in a device.
  • The end user cleared the application data, which then triggers the application to get a new token.

Activate the endpoint

For APNs, the Apple device notifies SNS that the credentials are expired, not valid, or revoked. Check the Apple Developer Portal to verify their status.

Reactivate the deactivated token

Don't activate a deactivated endpoint. SNS deactivates an application only if it determines that all messages sent to the application's endpoints will fail. Check if the token is valid. If it's not, first update it using SetEndpointAttributes. Then, activate it.

Reactivating an endpoint without updating its token works only when you uninstall and reinstall an application on the device with the same token.

Use this pseudo code for creating or activating the endpoint:

Retrieve the latest device token from the mobile operating system
if (the platform endpoint ARN isn't stored)
  # this is a first-time registration
  call create platform endpoint
  store the returned platform endpoint ARN
endif

call get endpoint attributes on the platform endpoint ARN

if (you get a not-found exception while getting the attributes)
  # the platform endpoint was deleted
  call create platform endpoint with the latest device token
  store the returned platform endpoint ARN
else
  if (the device token in the endpoint does not match the latest one) or
      (get endpoint attributes shows the endpoint as disabled)
    call set endpoint attributes to set the latest device token and then enable the platform endpoint
  endif
endif

Use the best practices found in Mobile App Events to keep a track of any platform endpoint change such as create, update, delete, or failure. The triggered notifications for such events can allow your application to take programmatic action when the particular event occurs.

For changes in the attributes of the platform endpoints, configure an SNS topic destination for EventEndpointUpdated on your SNS platform application. This example shows a payload for EventEndpointUpdated that's sent to the subscriber(s).

{
"EndpointArn": "arn:aws:sns:us-east-1:<account_ID>:endpoint/GCM/TestApplication/bdf172d4-f9b4-3b76-bc0b-f2XXXXXXXXXX",
"EventType": "EndpointUpdated",
"Resource": "arn:aws:sns:us-east-1:<account_ID>:app/GCM/TestApplication",
"Service": "SNS",
"Time": "2023-07-05T13:04:40.058Z",
"Type": "EndpointUpdated"
}

Related information

Why is my push platform application getting deactivated?

Troubleshooting

How do I access Amazon SNS topic delivery logs for push notifications?

How do I troubleshoot "DeviceTokenNotForTopic" errors when publishing APNs push notifications through Amazon SNS or Amazon Pinpoint?

How do I create an Android platform application in Amazon SNS for push notifications?

AWS OFFICIAL
AWS OFFICIALUpdated 10 months ago