I'm having a hard time understanding how SNS handles response messages. My SNS subscriber is a page that might go down or simply return a 4xx error.
For some reason though, it seems that SNS is treating requests that return 4xx error codes as successful.
How can I make it fail when the response code is 4xx and not only 5xx?
From the logs we can see that the subscriber is returning a status code 404 Not found, but despite that, the status of the request is still SUCCESS.
{
"notification": {
"messageMD5Sum": "fd746e97153916fd99bba*********",
"messageId": "be666c50-8de5-594b-9e77-*********",
"topicArn": "arn:aws:sns:us-east-1:060758096283:*********,
"timestamp": "2021-11-23 14:21:23.778"
},
"delivery": {
"deliveryId": "ef278086-2a70-5512-a191-da90d1534d24",
"redrivePolicy": "{\"deadLetterTargetArn\":\"arn:aws:sqs:us-east-1:*********:*********-DLQ\"}",
"destination": "*********/subscriber.php",
"providerResponse": "Not Found",
"dwellTimeMs": 80,
"attempts": 1,
"statusCode": 404
},
"status": "SUCCESS"
}
This is causing me issues with monitoring, as It's very hard to know if my requests are actually successful or not without manually looking them up.
SNS's job is to deliver a message to the endpoint. If the endpoint responds with a valid status code (not a 5XX failure), it considers the delivery of the message successful. How that message is responded to is up to the receiving API.
To be precise, only status codes outside of the range 200 - 499 will be considered as a failures and retried according to your retry policy as per https://docs.aws.amazon.com/sns/latest/dg/sns-message-delivery-retries.html. Once the max number of retries has been exhausted, the message will be delivered to a DLQ if one is configured.