Repository navigation
feat(aws-node-sqs-worker): bring the example to the standard with a live test - #841
Merged
Merged
Conversation
…reaches the dead-letter queue
…trimmed blocks show
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Brings
aws-node-sqs-workerto 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, nopackage.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
sqsevent. WithfunctionResponseType: ReportBatchItemFailuresthe worker returns only the messages it couldn't process, and the queue'sredrivePolicymoves 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
sqsevent docs and the SQS redrive docs for these.Changes
serverless.yml:produceronhttpApiPOST /jobs, withsqs:SendMessageon the jobs queue only;workeron thesqsevent withbatchSize: 10andfunctionResponseType: ReportBatchItemFailures. Thesqsevent doesn't create queues, so the jobs queue (VisibilityTimeout: 36,RedrivePolicywithmaxReceiveCount: 3) and the dead-letter queue (14-day retention) are underresources, both named with${sls:stage}. OutputDeadLetterQueueUrl.handler.mjsreplaceshandler.js;package.jsonandpackage-lock.jsonremoved (the SDK comes from the runtime).example.json: title, author and priority kept from the existing page;fasttier, onescriptcheck.test/smoke.mjs: posts a job with a task and one without through the HTTP API, waits for the worker'sProcessed job <id>: resize photo-<tag>.pngline, 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, rootREADME.md,examples.json: regenerated withnpm run docs.Test plan
us-east-1, Framework 4.47.0.PASS aws-node-sqs-worker 4.47.0 408s(stageexo6tqlz860):POST /jobs -> worker logged "Processed job d1e58077-…: resize photo-d12658eb.png"; job e761c584-… without a task -> dead-letter queue.PASS aws-node-sqs-worker 4.47.0 406s(stageexoqy2ynjo2).rotateinstead ofresize):FAIL zz-sqs-negative 4.47.0 416sat thecheckstep,no "Processed job …: rotate photo-f24dff3f.png" line within 120 s.aws sqs receive-messageread the failed job from the dead-letter queue; the output in the README comes from that run.Processed job …: resize photo-1.pngand 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.npm test(323 pass),npm run validate,npm run docs,npm run check-docsandcheck-examples.mjs --packageclean. The example has nopackage.json.Generated by Claude Code