Repository navigation
feat(aws-node-text-analysis-via-sns-post-processing): bring the example to the standard with a live test - #838
Merged
Merged
Conversation
…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.
…rints before the subscriber runs
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.
Lesson
An HTTP endpoint answers right away and leaves the work to a subscriber:
addNote(behindPOST /noteson an HTTP API) publishes each note to an SNS topic and returns202with the message ID;analyzeNote, subscribed to the topic through the Framework'ssnsevent, 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 namedtext-analysis-sns-<stage>-notes(it was a fixedanalyzeNote, so a second stage in the same account would reuse the name);httpApireplaces the RESThttpevent; the pinnedprovider.stageandregionare gone;sns:Publishis scoped to the topic's ARN.handler.mjsreplacesaddNote.jsandanalyzeNote.js: ES module, AWS SDK v3 from the runtime, a400for a body without anotestring, every record of the SNS event handled. Thesentimentdependency is replaced with built-in counts, so the example has nopackage.jsonand no install step.example.jsonwith ascriptcheck,test/smoke.mjs: posts a uniquely tagged note, takes the message ID from the response, waits foranalyzeNote's log line for that ID (aws logs filter-log-events) and asserts the exact counts. Title, author and priority are kept fromexamples.json.examples.jsonand the root README table updated bynpm run docs.Test plan
AWS account,
us-east-1, Framework 4.47.0.PASS aws-node-text-analysis-via-sns-post-processing 4.47.0 173s, stageexma2sowsk1, check linePOST /notes -> SNS message 658b4309-… -> analyzeNote logged "9 words, 2 sentences, 55 characters".3 sentencesinstead of2):FAIL aws-node-text-analysis-via-sns-post-processing 4.47.0 178s, stageexm6553otn3, failed stepcheck:expected "Analyzed note 169ab783-…: 9 words, 3 sentences, 55 characters"; got "… 9 words, 2 sentences, 55 characters".curl, the invalid-body case,serverless logs, remove). Deploy output, the202response, the400response and the logged analysis (9 words, 2 sentences, 52 characters) match the page.serverless logsrun within a second of the request printsNo existing streams for the function, and the log also holds the invocation'sSTART,ENDandREPORTlines; the README now says both.describe-stacksreports 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-docsandcheck-examples.mjs --packagepass.Generated by Claude Code