fix(cli): gen2-migration forward-direction function grants avoid circular deps - #14981
Open
sharonyajain wants to merge 1 commit into
Open
sharonyajain wants to merge 1 commit into
sharonyajain wants to merge 1 commit into
Conversation
sharonyajain
force-pushed
the
fix/gen2-migration-function-access-circular-deps
branch
from
August 27, 2026 12:38
8ab9bfd to
7387f96
Compare
soberm
reviewed
Sep 7, 2026
soberm
left a comment
Contributor
There was a problem hiding this comment.
Reviewed the forward-direction grant fix — approach is directionally correct and breaks the cross-stack cycle (grants land on the function role, referencing only the auth/storage ARN); consolidation/de-dup/sort logic is sound and the three regenerated snapshots match the generator output. A few non-blocking notes inline. Also worth flagging: validation is unit + snapshot only — a one-off live ampx sandbox deploy of a regenerated app would confirm the CloudformationStackCircularDependencyError is actually gone end-to-end.
sharonyajain
force-pushed
the
fix/gen2-migration-function-access-circular-deps
branch
from
September 7, 2026 12:56
7387f96 to
20af9e1
Compare
…ular deps
The generate command emitted a function's access to auth and storage as
reverse-direction constructs: `access: (allow) => [allow.resource(fn).to([...])]`
on defineAuth, and `allow.resource(fn)` entries in the defineStorage access
block. Both make the auth/storage stack reference the function's role, i.e. an
`auth -> function` / `storage -> function` cross-stack dependency. When the same
function also accesses another category (e.g. data or storage) the usual
`data -> auth` / `storage -> auth` edges close a cross-stack cycle, and the
generated Gen2 app fails to deploy with CloudformationStackCircularDependencyError.
Setting resourceGroupName only co-locates resources and cannot break a genuine
cross-category cycle.
Emit the grants in the forward direction in backend.ts instead, on the underlying
CDK constructs, so the dependency stays `function -> auth` / `function -> storage`:
- auth: `backend.auth.resources.userPool.grant(backend.<fn>.resources.lambda, ...)`
with a documented Amplify-permission -> cognito-idp action mapping (the CDK grant
works on raw IAM actions rather than Amplify permission names).
- storage: `backend.storage.resources.bucket.grant{Read,Write,ReadWrite,Delete}(...)`,
choosing the narrowest grant that covers the consolidated permission set.
Identity-based storage access (guest / authenticated / group) is unchanged and
still rendered as the per-path defineStorage access block; a bucket whose only
Gen1 access was function access now emits no access block at all.
Regenerated the fitness-tracker, media-vault, and store-locator migration-app
snapshots to reflect the forward-direction output.
sharonyajain
force-pushed
the
fix/gen2-migration-function-access-circular-deps
branch
from
September 8, 2026 12:53
20af9e1 to
8369312
Compare
6 tasks
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.
Description of changes
amplify gen2-migration generatecould produce a Gen2 app that fails to deploy with:Root cause. The generator emitted a function's access to auth/storage using
reverse-direction constructs:
access: (allow) => [allow.resource(fn).to([...])]ondefineAuthallow.resource(fn).to([...])entries inside thedefineStorageaccess blockBoth make the auth/storage stack reference the function's role — an
auth → function/storage → functioncross-stack dependency. When the samefunction also accesses another category (e.g.
data), and that categoryreferences auth (
data → auth), the reverse-direction grant closes a cross-stackcycle. Setting
resourceGroupNameonly co-locates resources in one stack andcannot break a genuine cross-category cycle.
Fix. Emit the grants in the forward direction in
backend.ts, on theunderlying CDK constructs, so the dependency stays
function → auth/function → storage:backend.auth.resources.userPool.grant(backend.<fn>.resources.lambda, ...cognito-idp actions), using a documented Amplify-permission →cognito-idp:*action mapping (the CDK grant works on raw IAM actions, not Amplify permission names).backend.storage.resources.bucket.grant{Read,Write,ReadWrite,Delete}(backend.<fn>.resources.lambda), picking the narrowest grant that covers the consolidated permission set.Identity-based storage access (guest / authenticated / group) is unchanged and
still rendered as the per-path
defineStorageaccess block; a bucket whose onlyGen1 access was function access now emits no access block at all.
Issue #, if available
Fixes #14727
Description of how you validated changes
auth.generator.test.tsands3.generator.test.tsrewritten to assert the forward-direction grants (spy onaddPostDefineBackendStatement) — 39/39 pass, 28/28 snapshots.adminfunction'saccessblock ondefineAuthis replaced bybackend.auth.resources.userPool.grant(backend.admin.resources.lambda, ...)inbackend.ts.media-vaultandstore-locatorsnapshots also updated.tsc --noEmitclean; eslint 0 errors on touched files; prettier clean.Not yet validated: a live
ampx sandboxdeploy of the regenerated output confirming the circular-dependency error is gone. That requires an AWS account and a multi-category Gen1 app; flagging it as the remaining manual-verification gate.One thing worth a maintainer's eye: the auth permission →
cognito-idp:*mapping duplicates expansion logic that lives inside@aws-amplify/backend-auth. It needs a sanity-check against that source and a note to keep the table in sync.Checklist
yarn testpasses (targeted gen2-migration generate suites; see above)By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.