Skip to content

feat(aws-node-sqs-worker): bring the example to the standard with a live test - #841

Merged
czubocha merged 3 commits into
v4from
branch/dreamy-lamport-709whe-sqs
Nov 25, 2026
Merged

czubocha merged 3 commits into
v4from
branch/dreamy-lamport-709whe-sqs

Conversation

@czubocha

Copy link
Copy Markdown
Contributor

Brings aws-node-sqs-worker to the example standard: manifest with a live test, README in the fixed sections with output from real runs, and code on the current idiom (Node.js 24, arm64, ES modules, the AWS SDK v3 the runtime includes, no package.json).

Lesson

An HTTP endpoint puts jobs on an SQS queue and answers at once; a worker function consumes the queue in batches through the Framework's sqs event. With functionResponseType: ReportBatchItemFailures the worker returns only the messages it couldn't process, and the queue's redrivePolicy moves a message that fails three times to a dead-letter queue, so a bad job doesn't come back forever.

The dead-letter queue and partial batch responses are part of the lesson here (the example is meant to be quoted by a tutorial on processing a queue), not additions.

Left out: FIFO queues, batching windows, filter patterns, maximum concurrency, redriving the dead-letter queue, alarms, auth on the endpoint. The README's Next steps link the sqs event docs and the SQS redrive docs for these.

Changes

  • serverless.yml: producer on httpApi POST /jobs, with sqs:SendMessage on the jobs queue only; worker on the sqs event with batchSize: 10 and functionResponseType: ReportBatchItemFailures. The sqs event doesn't create queues, so the jobs queue (VisibilityTimeout: 36, RedrivePolicy with maxReceiveCount: 3) and the dead-letter queue (14-day retention) are under resources, both named with ${sls:stage}. Output DeadLetterQueueUrl.
  • handler.mjs replaces handler.js; package.json and package-lock.json removed (the SDK comes from the runtime).
  • example.json: title, author and priority kept from the existing page; fast tier, one script check.
  • test/smoke.mjs: posts a job with a task and one without through the HTTP API, waits for the worker's Processed job <id>: resize photo-<tag>.png line, then waits for the second job's message ID in the dead-letter queue (and fails if the processed job shows up there).
  • README.md, root README.md, examples.json: regenerated with npm run docs.

Test plan

us-east-1, Framework 4.47.0.

  • Live test: PASS aws-node-sqs-worker 4.47.0 408s (stage exo6tqlz860): POST /jobs -> worker logged "Processed job d1e58077-…: resize photo-d12658eb.png"; job e761c584-… without a task -> dead-letter queue.
  • Live test after the last change to the smoke test: PASS aws-node-sqs-worker 4.47.0 406s (stage exoqy2ynjo2).
  • Negative control (scratch copy expecting rotate instead of resize): FAIL zz-sqs-negative 4.47.0 416s at the check step, no "Processed job …: rotate photo-f24dff3f.png" line within 120 s.
  • README followed by hand once: both curls returned 202, the worker logged the processed job and three failed receives 36 seconds apart, and aws sqs receive-message read the failed job from the dead-letter queue; the output in the README comes from that run.
  • Fresh-agent test: an agent given only the README deployed the example, got 202 for both jobs and 400 for a non-JSON body, saw Processed job …: resize photo-1.png and three failed receives in the logs, read the failed job from the dead-letter queue about 2 minutes after sending it, removed the example and confirmed the stack was gone.
  • Nothing left after the runs: no stack, queue or log group from the example.
  • npm test (323 pass), npm run validate, npm run docs, npm run check-docs and check-examples.mjs --package clean. The example has no package.json.

Generated by Claude Code

@czubocha
czubocha merged commit f18b5de into v4 Nov 25, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant