Skip to content

feat(aws-node-text-analysis-via-sns-post-processing): bring the example to the standard with a live test - #838

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

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

Conversation

@czubocha

Copy link
Copy Markdown
Contributor

Lesson

An HTTP endpoint answers right away and leaves the work to a subscriber: addNote (behind POST /notes on an HTTP API) publishes each note to an SNS topic and returns 202 with the message ID; analyzeNote, subscribed to the topic through the Framework's sns event, counts the note's words, sentences and characters and logs them.

Left out: filter policies, a dead-letter queue, an SQS fan-out and persisting results. Each is a separate lesson; the README's Next steps link to the SNS event docs and to the SQS and DynamoDB examples.

What changed

  • serverless.yml: the topic is named text-analysis-sns-<stage>-notes (it was a fixed analyzeNote, so a second stage in the same account would reuse the name); httpApi replaces the REST http event; the pinned provider.stage and region are gone; sns:Publish is scoped to the topic's ARN.
  • handler.mjs replaces addNote.js and analyzeNote.js: ES module, AWS SDK v3 from the runtime, a 400 for a body without a note string, every record of the SNS event handled. The sentiment dependency is replaced with built-in counts, so the example has no package.json and no install step.
  • example.json with a script check, test/smoke.mjs: posts a uniquely tagged note, takes the message ID from the response, waits for analyzeNote's log line for that ID (aws logs filter-log-events) and asserts the exact counts. Title, author and priority are kept from examples.json.
  • README restructured into the standard sections, with output from a real run; generated frontmatter, examples.json and the root README table updated by npm run docs.

Test plan

AWS account, us-east-1, Framework 4.47.0.

  • Live test: PASS aws-node-text-analysis-via-sns-post-processing 4.47.0 173s, stage exma2sowsk1, check line POST /notes -> SNS message 658b4309-… -> analyzeNote logged "9 words, 2 sentences, 55 characters".
  • Negative control (expected 3 sentences instead of 2): FAIL aws-node-text-analysis-via-sns-post-processing 4.47.0 178s, stage exm6553otn3, failed step check: expected "Analyzed note 169ab783-…: 9 words, 3 sentences, 55 characters"; got "… 9 words, 2 sentences, 55 characters".
  • README followed literally from a clean copy of the branch (deploy, curl, the invalid-body case, serverless logs, remove). Deploy output, the 202 response, the 400 response and the logged analysis (9 words, 2 sentences, 52 characters) match the page. serverless logs run within a second of the request prints No existing streams for the function, and the log also holds the invocation's START, END and REPORT lines; the README now says both.
  • Leftovers after all runs: describe-stacks reports no stack for any of the stages; no SNS topic, /aws/lambda/text-analysis-sns* log group, Lambda function or HTTP API named for the service remains.
  • npm test (323 pass), npm run validate, npm run check-docs and check-examples.mjs --package pass.

Generated by Claude Code

…le to the standard with a live test

Publish notes from an HTTP API to a stage-named SNS topic that a subscriber function analyzes. Replace the sentiment dependency with built-in counts, add example.json with a smoke test that follows a note from the API to the subscriber's log, and restructure the README.
@czubocha
czubocha merged commit b7d5910 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