liveBook · Manning

Visibility timeout

As explained in Amazon Web Services in Action, Third Edition: An in-depth guide to AWS

A visibility timeout is a queue setting that temporarily hides a received message from other consumers while it is being processed.

A visibility timeout is an Amazon SQS setting that temporarily hides a received message while a worker processes it. The worker must finish the task and delete the message before the timeout expires; otherwise, SQS makes the message available again. section 14.2.5

Configure the timeout as part of the worker’s receive operation:

  • Set VisibilityTimeout in seconds. A practical starting point is roughly four times the average processing time. section 14.2.5
  • Process the received message within that period. section 14.2.5
  • Delete the message with its ReceiptHandle after successful processing; deletion acknowledges completion. section 14.2.5

URL-to-PNG worker

A Node.js worker receives one SQS message with VisibilityTimeout set to 120 seconds, uses Puppeteer to capture the requested website, uploads the PNG to S3, and then deletes the message. If the work exceeds 120 seconds, the message becomes visible and may be processed again. section 14.2.5 section 14.2.6

Visibility timeout supports at-least-once processing rather than exactly-once delivery. Make processing idempotent where possible, and use a dead-letter queue when repeated failures would otherwise leave a message retrying indefinitely. section 14.2.6 section 16.3.4

Listing 14.5 worker.js: Receiving a message from the queue
const fs = require('fs');
const AWS = require('aws-sdk');
const puppeteer = require('puppeteer');
const config = require('./config.json');
const sqs = new AWS.SQS();
const s3 = new AWS.S3();
  
async function receive() {
  const result = await sqs.receiveMessage({   #1
    QueueUrl: config.QueueUrl,
    MaxNumberOfMessages: 1,                   #2
    VisibilityTimeout: 120,                   #3
    WaitTimeSeconds: 10                       #4
  }).promise();
 
  if (result.Messages) {                      #5
    return result.Messages[0]                 #6
  } else {
    return null;
  }
};

The worker listing shows VisibilityTimeout alongside batch size and long polling, making the receive configuration concrete. section 14.2.5

How Amazon Web Services in Action, Third Edition: An in-depth guide to AWS covers it

How deep it goes
Explains configuration, sizing, acknowledgment, retries, and idempotence, but does not detail timeout extension mechanisms.
Examples
Demonstrates a 120-second Node.js worker that screenshots websites with Puppeteer, uploads images to S3, and deletes messages.
What it assumes
Assumes basic queue consumption and worker processing, while defining receipt handles, timeout expiry, retries, and idempotence.
What you can do after
Operate/configure an SQS worker that sizes a visibility timeout and acknowledges successful work safely.
How it connects
Connects Amazon SQS with message acknowledgment, at-least-once delivery, idempotent processing, long polling, and dead-letter queues.

Also explained in

Compare how 2 books explain visibility timeout →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Amazon Web Services in Action, Third Edition: An in-depth guide to AWS. The section links point to the parts of the book it draws on.