feat: automatic nested stack partitioning for large schemas - #3437
feat: automatic nested stack partitioning for large schemas#3437praneetap wants to merge 1 commit into
Conversation
Implements automatic partitioning of AppSync resolvers across multiple nested CloudFormation stacks to solve the 1MB template size limit. **What Changed:** - Added PartitioningNestedStackProvider for intelligent resource distribution - Extended AmplifyGraphqlApiProps with enableAutoPartitioning and partitioningConfig - Added comprehensive unit and integration tests **How It Works:** - PRIMARY stack: API + Tables + DataSources (minimizes cross-stack refs) - RESOLVER stacks: Distributed resolvers (max 200 per stack) - Automatic overflow creation when capacity thresholds reached - Groups related resolvers by GraphQL type for efficiency **CloudFormation Limits Managed:** - Template Size: 750KB threshold per stack - Resources: 450 resource threshold (500 limit) - Outputs: 150 output threshold (200 limit) - avoided via architecture - Parameters: Minimal usage (resolvers reference via parent scope) **Configuration:** - enableAutoPartitioning (default: false for opt-in) - partitioningConfig for advanced tuning - CDK context support: amplify-data-auto-partition **Tests:** - Unit tests for PartitioningNestedStackProvider (17 test cases) - Integration tests for AmplifyGraphqlApi (15 test cases) - Edge case coverage and configuration validation Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Add ACTIVE_nested-stack-partitioning.md with PR #3437 analysis, correct integration point, and design constraints - Add Active Work Tracking section to AGENTS.md with lifecycle rules - Add Active Work section to .agent-docs/README.md index
…appings infrastructure - Add precise GitHub links for every claim about the call chain - Document existing stackMappings feature as the foundation to build on - Trace the full flow: AmplifyGraphqlApiProps → ExecuteTransformConfig → GraphQLTransform → TransformerContext → StackManager.resourceToStackMap - Key insight: we just need to compute stackMappings automatically, zero changes needed to StackManager or any transformer
|
This seems to be a long awaited change request. On behalf of myself and any other amplify user to have experienced this hard limit that stalls projects entirely I kindly ask to top up priority |
|
I'm getting TooManyResourcesInStack error for "data/amplifyData/FunctionDirectiveStack" 541 is greater than allowed maximum of 500: AWS::IAM::Role (90), AWS::IAM::Policy (90), AWS::AppSync::DataSource (90), AWS::AppSync::FunctionConfiguration (180), AWS::AppSync::Resolver (90), AWS::CDK::Metadata (1) We are in a desperate need for this feature. We're blocked right now and don't know how to proceed. Please, resolve this issue asap, so that we can continue to build our application |
|
Are there any updates on this PR? |
|
Hi Amplify team, Could someone please take a look at this PR when possible? The issue it addresses has been open for quite some time and continues to affect users in production environments. A review, feedback, or an update on next steps would be greatly appreciated. Thank you for your time and for maintaining Amplify. |
Automatic Nested Stack Partitioning for Large Schemas
Summary
Implements automatic partitioning of AppSync resolvers across multiple nested CloudFormation stacks to solve the 1MB template size limit issue affecting Amplify Gen 2 customers with large schemas.
Fixes:
Problem
Customers with large schemas (100+ types, many custom resolvers) encounter CloudFormation's 1MB template size limit during deployment:
Current workarounds require:
Solution
Automatic partitioning of AppSync resolvers across multiple nested stacks:
Each nested stack has its own 1MB limit, effectively multiplying available template space.
Why This Architecture?
We keep tables and data sources in the Primary stack (not separate stacks) to avoid the 200 output limit bottleneck:
Our solution:
CloudFormation Limits Addressed
Key Features
1. Opt-In for CDK Users
2. Intelligent Distribution
3. Configurable
4. CDK Context Support
Implementation Details
Core Changes
1. New
PartitioningNestedStackProviderClasspackages/amplify-graphql-api-construct/src/internal/partitioning-nested-stack-provider.ts(416 lines)Intelligent nested stack provider that:
2. Modified
AmplifyGraphqlApiConstructorpackages/amplify-graphql-api-construct/src/amplify-graphql-api.tsenableAutoPartitioningandpartitioningConfigpropsPartitioningNestedStackProviderwhen enabled3. Extended Type Definitions
packages/amplify-graphql-api-construct/src/types.tsAdded:
PartitioningConfiginterface with full documentationenableAutoPartitioning?: booleantoAmplifyGraphqlApiPropspartitioningConfig?: PartitioningConfigtoAmplifyGraphqlApiProps4. Public API Exports
packages/amplify-graphql-api-construct/src/index.tsExported
PartitioningConfigtype for external consumersTesting
Unit Tests (17 test cases)
src/__tests__/internal/partitioning-nested-stack-provider.test.tsIntegration Tests (15 test cases)
src/__tests__/__functional__/partitioning.test.tsMigration Guide
For CDK Users (Opt-In)
For Existing Deployments
No breaking changes - partitioning is opt-in via
enableAutoPartitioning: trueor CDK context flag.Stack References
If you reference stacks by name:
Performance Impact
Deployment Time
Trade-off: Slightly longer deployment vs. successful deployment
Runtime Performance
Metrics & Monitoring
Console output shows partitioning statistics:
Warnings when approaching limits:
Checklist
Related PRs
Testing Instructions
Test Case 1: Small Schema (No Partitioning)
Test Case 2: Integration Tests
npm test -- partitioning.test.tsTest Case 3: Manual CDK Test
Customer Impact
Before This PR:
After This PR:
This unblocks dozens of customers currently stuck at template size limits.
Questions for Reviewers
Default behavior: Currently
enableAutoPartitioningdefaults tofalse(opt-in). Should we make ittrueby default in a future major version?Stack naming: Names
DataPrimary,DataResolvers0,DataResolvers1- are these acceptable?Resolver grouping: Currently groups related resolvers (same type) together. Any concerns?
Export limits: Not currently tracking exports (200 limit). Our architecture avoids exports, but should we add explicit tracking?
Template size estimation: Currently uses heuristic (3KB per resolver). Should we implement actual template synthesis for accurate measurement in a future iteration?