DeleteMessage

Description

The DeleteMessage action deletes the specified message from the specified queue. You specify the message by using the message's receipt handle and not the message ID you received when you sent the message. Even if the message is locked by another reader due to the visibility timeout setting, it is still deleted from the queue. If you leave a message in the queue for more than 4 days, SQS automatically deletes it.

[Note]Note

The receipt handle is associated with a specific instance of receiving the message. If you receive a message more than once, the receipt handle you get each time you receive the message is different. When you request DeleteMessage, if you don't provide the most recently received receipt handle for the message, the request will still succeed, but the message might not be deleted.

[Important]Important

It is possible you will receive a message even after you have deleted it. This might happen on rare occasions if one of the servers storing a copy of the message is unavailable when you request to delete the message. The copy remains on the server and might be returned to you again on a subsequent receive request. You should create your system to be idempotent so that receiving a particular message more than once is not a problem.

Request Parameters

The following table lists the special request parameters the DeleteMessage action uses in addition to the common parameters all actions use (for more information, see Request Parameters Common to All Actions).

NameDescriptionRequired

ReceiptHandle

The receipt handle associated with the message you want to delete.

Type: String

Yes

Response Elements

The response contains no special elements besides the common elements returned in all successful responses (for more information, see Structure of a Successful Response).

Special Errors

The request doesn't fail unless the ReceiptHandle is malformed. Even if the specified ReceiptHandle doesn't exist or isn't the most recently returned receipt handle for that message, the action returns Success.

Examples

The following example Query request deletes a message from the specified queue.

Sample Request

http://queue.amazonaws.com/queue1
?Action=DeleteMessage
&AWSAccessKeyId=0GS7553JW74RRM612K02EXAMPLE
&Version=2008-01-01
&ReceiptHandle=Z2hlcm1hbi5kZXNrdG9wLmFtYXpvbi5jb20=:AAABFoNJa/AAAAAAAAAANwAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAHA=
&Expires=2008-02-10T12:00:00Z
&Signature=CN2SbNq2B2Vw1W3lbc7wpM5gzDHEXAMPLE
&SignatureVersion=2
&SignatureMethod=HmacSHA256

Sample Response

<DeleteMessageResponse>
  <ResponseMetadata>
    <RequestId>cb919c0a-9bce-4afe-9b48-9bdf2412bb67</RequestId>
  </ResponseMetadata>
</DeleteMessageResponse>

Related Actions