Amazon Web Services (AWS) - Delete Simple Queue Service (SQS) Message using the AWS CLI

by
Jeremy Canfield |
Updated: October 28 2024
| Amazon Web Services (AWS) articles
This assumes you have already configured the aws command line tool. If not, check out my article on Getting Started with the AWS CLI.
If you are not familiar with AWS Simple Queue Service (SQS), check out my article Amazon Web Services (AWS) - Getting Started with Simple Queue Service (SQS).
The aws sqs list-queues command can be used to list your queues.
~]$ aws sqs list-queues
{
"QueueUrls": [
"https://queue.amazonaws.com/123456789012/my-first-queue"
]
}
Likewise, the aws sqs get-queue-url command can be used to get the URL of your queue.
~]$ aws sqs get-queue-url --queue-name my-first-queue
{
"QueueUrl": "https://queue.amazonaws.com/123456789012/my-first-queue"
}
And then the aws sqs receive-message command can be used to get the message from the queue. The body is "hello".
~]$ aws sqs receive-message --queue-url https://queue.amazonaws.com/123456789012/my-first-queue
{
"Messages": [
{
"Body": "hello",
"ReceiptHandle": "AQEBqy3nHXKLjlXFCw7ZMky0z6bMgEG0MvvnNBLnQ/1drFX+9Oqh291bmiu3AqQjKni+REeYhyidtW5m+blD5WDA66dqfmGsk6q79jfrZf5GjNwgWU7FNJlm6//Sw21HdezqygzlM4slAQ54URQ9CqaTTUSmjWK6rwPuXrG1ULswGdUzp2ZNtxvSUy1km+nLy7Yp9rGhwUAX3vJlAZAGKKvce6owT/Tnf/uSi68dpv91mJH6LR23QUOdnBk8Bgl1v1SF1QkIo+DiMhY3/IoSu9FpnCZj3rSbafY32FcTLmqfctuVGAJnU9mkNRQuCMATFoSVkkjAgOrKjUZaQMZ6eyNdIS+l67N2QNbUpgsBBQtLaGg8CBHIkGCGJkKV+/ekgUXWj6/godVCkgOwo/hEeZeegQ==",
"MD5OfBody": "5d41402abc4b2a76b9719d911017c592",
"MessageId": "5508026b-e650-45d8-8482-8d13623d6a6b"
}
]
}
Then the aws sqs delete-message can be used to delete the message from the queue.
aws sqs delete-message --queue-url https://sqs.us-east-1.amazonaws.com/123456789012/my-first-queue --receipt-handle "AQEBqy3nHXKLjlXFCw7ZMky0z6bMgEG0MvvnNBLnQ/1drFX+9Oqh291bmiu3AqQjKni+REeYhyidtW5m+blD5WDA66dqfmGsk6q79jfrZf5GjNwgWU7FNJlm6//Sw21HdezqygzlM4slAQ54URQ9CqaTTUSmjWK6rwPuXrG1ULswGdUzp2ZNtxvSUy1km+nLy7Yp9rGhwUAX3vJlAZAGKKvce6owT/Tnf/uSi68dpv91mJH6LR23QUOdnBk8Bgl1v1SF1QkIo+DiMhY3/IoSu9FpnCZj3rSbafY32FcTLmqfctuVGAJnU9mkNRQuCMATFoSVkkjAgOrKjUZaQMZ6eyNdIS+l67N2QNbUpgsBBQtLaGg8CBHIkGCGJkKV+/ekgUXWj6/godVCkgOwo/hEeZeegQ=="
Did you find this article helpful?
If so, consider buying me a coffee over at