Skip to content

feat: add AppSync DynamoDB example, bring S3 upload example to the standard - #837

Merged
czubocha merged 1 commit into
v4from
branch/dreamy-lamport-709whe-guides-examples
Nov 25, 2026
Merged

czubocha merged 1 commit into
v4from
branch/dreamy-lamport-709whe-guides-examples

Conversation

@czubocha

Copy link
Copy Markdown
Contributor

What this changes

aws-node-upload-to-s3-and-postprocess (upgraded to the example standard)

Lesson: an upload to S3 invokes a function, through the Framework's s3 event, and the function processes the new object.

  • An upload under uploads/ invokes postprocess (nodejs24.x, arm64, ES module, AWS SDK v3 from the runtime), which reads the object and writes a JSON summary (bytes, lines, words, SHA-256) to processed/<name>.json.
  • The s3 event has a prefix: uploads/ rule; results go to processed/, so the function's own writes don't invoke it.
  • The bucket name is upload-postprocess-${sls:stage}-${aws:accountId}; its name is a stack output, UploadBucketName.
  • The function role allows s3:GetObject on uploads/* and s3:PutObject on processed/* only (was s3:* on *).
  • service is now s3-postprocess (14 characters), so the Lambda role name stays under 64 characters in every Region with a test stage.
  • example.json with a script check (test/smoke.mjs), a README in the fixed sections, and the catalogue entries regenerated with npm run docs. Title, author and priority are kept; the description now matches what the example does.

Left out: the HTML upload form and generate-form.js (it needed AWS access keys in a local file to sign a POST policy, plus the crypto-js dependency), image-specific processing such as thumbnails (needs a native dependency), a second bucket for results, and dead-letter handling.

aws-node-appsync-dynamodb (new)

Lesson: the built-in v4 appSync block deploys a GraphQL API with no plugin: API key auth, a DynamoDB data source and two APPSYNC_JS unit resolvers (createPost, getPost).

  • Based on the AppSync quick start in the Framework docs; the API name includes the stage.
  • Stack outputs GraphQlApiUrl and GraphQlApiKey from ${appsync:url} and ${appsync:apiKey.defaultKey}, for the test script and tools that read outputs.
  • No Lambda functions and no dependencies: the Framework bundles the resolvers and leaves @aws-appsync/utils to the AppSync runtime.

Left out: Cognito or IAM auth, pipeline resolvers, Lambda resolvers, subscriptions, caching, custom domains.

Test plan

AWS us-east-1, Serverless Framework 4.47.0.

Static: npm test (323 pass, 0 fail), npm run validate (0 errors), npm run check-docs (clean), node scripts/check-examples.mjs <dir> --package for both (0 errors). No package.json dependencies in either example, so nothing for npm audit.

Run Stage Result
S3, negative control (copy expecting words: 12) exkf4spamr2 FAIL neg-s3 4.47.0 109s at check: expected words 12; got 11
S3, live test exkhjygbsy3 PASS aws-node-upload-to-s3-and-postprocess 4.47.0 106s
AppSync, negative control (copy expecting a changed title) exknh1ckikq FAIL neg-appsync 4.47.0 99s at check: getPost(...) title mismatch
AppSync, live test exkpoack8j4 PASS aws-node-appsync-dynamodb 4.47.0 98s

Passing check lines:

s3://upload-postprocess-exkhjygbsy3-<account>/uploads/smoke-c44b1362.txt -> processed/smoke-c44b1362.txt.json: 72 bytes, 2 lines, 11 words, sha256 9e80570b1ae5...
https://<api>.appsync-api.us-east-1.amazonaws.com/graphql: createPost returned 9ca5369d-...; getPost read back "Hello from the smoke test 93c32620"; unknown ID null; no API key 401

Both READMEs were followed literally from a clean copy, each command as the page shows it plus a unique --stage: the deploy output, serverless info, the curl requests (create, read back, unknown ID null, no key 401), the S3 upload, the summary JSON, serverless logs and the cleanup commands all matched the page, with no step needing a guess. After the runs, describe-stacks reports does not exist for every stack, and no s3-postprocess log group, upload-postprocess-* bucket, appsync-dynamodb-* API or table is left.


Generated by Claude Code

…andard

Add aws-node-appsync-dynamodb: an AppSync GraphQL API from the built-in appSync block, with API key auth and two APPSYNC_JS resolvers (createPost, getPost) on a DynamoDB table, and a live test that creates a post and reads it back.

Rework aws-node-upload-to-s3-and-postprocess: an upload under uploads/ triggers a Node.js 24 function that reads the object and writes a summary under processed/. The bucket name carries the stage and account ID, the s3 event uses a prefix rule, the function role is limited to the two prefixes, and a live test uploads a file and checks the summary. The HTML form and its signing script, which needed AWS keys in a local file, are removed.
@czubocha
czubocha merged commit 6270369 into v4 Nov 25, 2026
4 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