Skip to content

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 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 the message in FIFO (First-In-First-Out) and standard queues. When you delete or change the visibility of the message, you must use the receipt handle.

If you use an incorrect or expired receipt handle, then you get one of the following error messages:

  • "An error occurred (ReceiptHandleIsInvalid) when calling the DeleteMessage operation: The input receipt handle 'YOUR RECEIPT HANDLE' is not a valid receipt handle."
  • "An error occurred (ReceiptHandleIsInvalid) when calling the DeleteMessage operation: The receipt handle "YOUR RECEIPT HANDLE" is not valid for this queue."
  • "An error occurred (InvalidParameterValue) when calling the DeleteMessage operation: Value 'YOUR RECEIPT HANDLE' for parameter ReceiptHandle is invalid. Reason: The receipt handle has expired."

Important: It's a best practice to use the latest receipt handle for DeleteMessage API operations. However, older receipt handles might succeed when you use standard SQS queues.

Resolution

Resolve "ReceiptHandleIsInvalid" errors

To resolve this issue, use the correct receipt handle and make sure that it's for the SQS queue that contains the message.

If you receive a message multiple times, then review the most recent ReceiveMessage API operation response and identify the ReceiptHandle value. Then, use the ReceiptHandle value when you call the DeleteMessage API operation.

Resolve "InvalidParameterValue" errors

After a visibility timeout period, a receipt handle expires and the message returns to the queue. When you receive the message again from a consumer, you get a new receipt handle.

To resolve the InvalidParameterValue error, make sure that you use the receipt handle to delete the message within the SQS queue visibility timeout period.

Related information

Amazon SQS best practices