How do I troubleshoot "ReceiptHandleIsInvalid" and "InvalidParameterValue" errors when I use the Amazon SQS DeleteMessage API call?

2 minute read
0

I receive a "ReceiptHandleIsInvalid" or "InvalidParameterValue" error when I try to delete messages from my Amazon Simple Queue Service (Amazon SQS) queue.

Short description

When you receive a message from an Amazon SQS queue, you also receive a receipt handle for that message for FIFO (First-In-First-Out) and standard queues. The receipt handle is required when you delete or change the visibility of the message.

If the receipt handle is incorrect, then you receive an error similar to this example:

"An error occurred (ReceiptHandleIsInvalid) when calling the DeleteMessage operation: The input receipt handle 'YOUR RECEIPT HANDLE' is not a valid receipt handle."

If the receipt handle is expired, then you receive an error similar to this example:

"An error occurred (InvalidParameterValue) when calling the DeleteMessage operation: Value 'YOUR RECEIPT HANDLE' for parameter ReceiptHandle is invalid. Reason: The receipt handle has expired."

A receipt handle expires after a visibility timeout period. When a visibility timeout expires, the message returns to the queue. When you receive the message again from a consumer, you get a new receipt handle. This error occurs because you used an older receipt handle instead of the latest receipt handle.

Note: Older receipt handles might succeed when you use standard SQS queues. However, it's a best practice to use the latest receipt handle for DeleteMessage API calls.

Resolution

To prevent incorrect or expired receipt handle errors, use the correct receipt handle to delete the message within the SQS queue visibility timeout period.

If you receive a message more than once, review the most recent ReceiveMessage API call response, and identify the ReceiptHandle value. Then, use the identified ReceiptHandle value when you make the DeleteMessage API call.

Also, you might receive this error when you make the DeleteMessage API call:

"An error occurred (ReceiptHandleIsInvalid) when calling the DeleteMessage operation: The receipt handle "YOUR RECEIPT HANDLE" is not valid for this queue."

This error occurs when you try to delete a message with a receipt handle that's from a different SQS queue. To prevent this error, use the correct receipt handle from the SQS queue where the message is.

Related information

Best practices for Amazon SQS

AWS OFFICIAL
AWS OFFICIALUpdated 5 months ago