Amazon SQS / Practical

Try SQS on AWS.

Create one queue, send a message, receive it, and delete it from the AWS Console.

1. Prepare your AWS account

Create or sign in to an AWS account using the AWS Free Tier page ↗. AWS may ask for email, phone, and payment verification. Free Tier limits and eligibility can change, so review the current terms and billing dashboard.

For this first exercise, use the AWS Console. Do not create long-lived root access keys. If you later use the AWS CLI, use an appropriate IAM identity with only the permissions needed for SQS.

2. Create a queue

  1. Open the Amazon SQS Console ↗.
  2. Choose the AWS Region you want to use. Stay in the same region for the whole exercise.
  3. Choose Create queue.
  4. Select Standard.
  5. Enter order-payment-queue as the name.
  6. Leave the other settings at their defaults for now and choose Create queue.

Open the queue and keep its details page available. The queue URL identifies this queue when an application sends or receives messages.

3. Send a message

In the queue page, choose Send and receive messages. In the message body, enter:

{"event":"PaymentRequested","orderId":"ORD-101","amount":450}

Choose Send message. SQS now stores the message in the queue. The producer could be an Order Service sending work to a Payment Service.

4. Receive and delete the message

In the same screen, choose Poll for messages. SQS returns the message to the console. It becomes temporarily invisible while it is being processed.

Imagine that a Payment Service has successfully handled the request. Choose the message and select Delete. Deleting is the acknowledgement: it tells SQS that the work completed successfully.

If the consumer fails before deletion, the message becomes visible again after the visibility timeout and can be received again. For that reason, consumers should be idempotent: processing the same message twice should not charge the customer twice.

5. Create and configure a dead-letter queue

A dead-letter queue, or DLQ, stores messages that repeatedly fail processing. It keeps a broken message from being retried forever in the normal queue.

Create the DLQ

  1. Return to the SQS queue list and choose Create queue.
  2. Choose Standard, because order-payment-queue is a Standard queue.
  3. Name it order-payment-dlq.
  4. Choose Create queue.

Keep the source queue and DLQ in the same AWS Region. A dead-letter queue should normally have enough retention time for the team to investigate failed messages.

Configure the order queue

  1. Open order-payment-queue and choose Edit.
  2. Find the Dead-letter queue or Redrive policy setting.
  3. Enable the policy and select order-payment-dlq as the dead-letter queue.
  4. Set Maximum receives to 3 for this exercise.
  5. Save the changes.

Now SQS counts unsuccessful receives for a message. After the message reaches the configured receive limit, SQS moves it from order-payment-queue to order-payment-dlq. A worker can later inspect the DLQ and decide whether to fix and redrive the message.

To test it, send a message, poll it without deleting it, wait for the visibility timeout, and repeat until it reaches the receive limit. Then open order-payment-dlq and poll for the moved message.

6. See the visibility timeout

Send another test message and poll for it. Do not delete it. While its visibility timeout is active, another poll may not show it. Wait for the timeout to expire, then poll again. The message should become available again.

For a real worker, choose a timeout longer than the normal processing time. A worker can extend the timeout when a long-running task needs more time.

7. Clean up

When you finish, return to the SQS queue list, select order-payment-queue, and choose Delete. Confirm the deletion. Also review the AWS Billing dashboard and remove any other practice resources you created.

This exercise follows the official AWS SQS getting-started guide ↗.