feat(examples): add minimal CRUD API example backed directly by DynamoDB#264
Open
laazyj wants to merge 2 commits into
Open
feat(examples): add minimal CRUD API example backed directly by DynamoDB#264laazyj wants to merge 2 commits into
laazyj wants to merge 2 commits into
Conversation
Adds ComposureCDK-CrudApiStack, demonstrating API Gateway wired straight to DynamoDB via AwsIntegration/VTL mapping templates — no Lambda in the request path. Grants the API's execution role least-privilege access to the table via table.grantReadWriteData() in an afterBuild hook. Also adds a DynamoDB TableV2 removal-policy injector to cleanDeskPolicy so the new example's table can be torn down in CI, and a smoke test that exercises the full create/read/update/delete lifecycle against a live deployment.
Adds grantReadData/grantWriteData/grantReadWriteData to createTableBuilder and createTableV2Builder, accepting a Resolvable<IGrantable> so a sibling component's role can be granted access via ref() and applied during the table's own build() — the same declarative pattern as the Neptune cluster builder's allowAccessFrom(), instead of an imperative afterBuild hook. Updates the crud-api-app example to use table.grantReadWriteData(ref(...)) and inlines its API resource tree directly into the compose() call, so the HTTP verb -> DynamoDB action -> VTL mapping for each method is visible at its addMethod call site rather than hidden behind a helper function.
laazyj
commented
Jul 4, 2026
| tableAndRole: ["table", "apiRole"], | ||
| api: ["tableAndRole"], | ||
| }, | ||
| ).build(stack, "CrudApiApp"); |
Owner
Author
There was a problem hiding this comment.
This is terrible. We'll work on it some more
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.
What & why
Adds
ComposureCDK-CrudApiStack, a new example demonstrating the minimal possible CRUD API: API Gateway wired directly to DynamoDB viaAwsIntegration/VTL mapping templates — no Lambda in the request path. This exercises the parts of ComposureCDK the request asked to highlight:createTableV2Builderfor the item store (a "gadgets" catalog — the business domain is arbitrary), keyed onid.createServiceRoleBuilder("apigateway.amazonaws.com")for the role API Gateway assumes to call DynamoDB.createRestApiBuilderwiring each HTTP verb (GET/POSTon/gadgets,GET/PUT/DELETEon/gadgets/{id}) straight to a DynamoDB action (Scan,PutItem,GetItem,DeleteItem) — the resource tree is declared directly inside thecompose()call, so every path/verb/action/VTL mapping is visible at itsaddMethodcall site.New declarative grant API in
@composurecdk/dynamodb. The example's IAM wiring needed a table to grant access to a role built by a sibling component. Rather than reach for an imperativeafterBuildhook, this PR addsgrantReadData/grantWriteData/grantReadWriteDatatocreateTableBuilderandcreateTableV2Builder, each accepting aResolvable<IGrantable>— the same declarative pattern as the Neptune cluster builder'sallowAccessFrom(ref(...)). The grant is queued at configuration time (table.grantReadWriteData(ref("apiRole", r => r.role))) and applied inside the table's ownbuild()once the role resolves. Backed by a small sharedTableGrantsqueue (packages/dynamodb/src/table-grants.ts) used by both builders, with unit tests covering concrete andRefgrantees plus.copy()preservation.Also included, per the existing example conventions:
bin/app.tsand thepackages/examples/README.mdstack table.TableV2removal-policyIPropertyInjectoradded tocleanDeskPolicy(this is the first example to use a DynamoDB table, and the doc comment there called out DynamoDB as a known gap) so the table can be torn down in CI.test/crud-api-app.test.ts) covering the resource tree, theAwsIntegrationwiring, and the IAM grant.test/smoke/crud-api.smoke.mjs) that exercises the full create → read → update → delete lifecycle against a live deployment, since this stack's runtime surface is the CRUD flow itself.Checklist
npm run verifypasses locally