Handling 5xx webhook retries with a dead letter queue

My Lambda consumer is throwing 502s on large payloads, which causes Genesys to retry indefinitely. Need a clean way to push these failures to an SQS dead letter queue after three attempts instead of letting the platform retry forever. Any examples of the retry logic or event structure?