Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to split Amplify project into multiple stacks. Error - Limit on the number of resources in a single stack operation exceeded #13536

Closed
2 tasks done
BBopanna opened this issue Jan 15, 2024 · 15 comments
Labels
cloudformation Issues related to CloudFormation workflow custom-cdk Issues related to custom CDK resource functionality pending-triage Issue is pending triage

Comments

@BBopanna
Copy link

BBopanna commented Jan 15, 2024

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v18.17.1

Amplify CLI Version

12.0.3

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

NO

Describe the bug

We are getting this error on an amplify project - "Limit on the number of resources in a single stack operation exceeded".

Question is simple - How to split Amplify project into multiple stacks. Are there any documentation with references/examples ?

Expected behavior

References/Documentation on - "How to split Amplify project into multiple stacks"

Reproduction steps

Create an amplify project with AppSync GraphyQL API with 50+ entities and add around 6+ custom resource which build around 30 custom resolvers and try to amplify push to get the error - "Limit on the number of resources in a single stack operation exceeded"

Project Identifier

No response

Log output

# Put your logs below this line


Additional information

No response

Before submitting, please confirm:

  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • I have removed any sensitive information from my code snippets and submission.
@BBopanna BBopanna added the pending-triage Issue is pending triage label Jan 15, 2024
@ykethan
Copy link
Member

ykethan commented Jan 16, 2024

Hey @BBopanna, thank you for reaching out. Currently, GraphQL API does provides support for splitting resolvers into custom named stack; documentation.

@ykethan ykethan added pending-response Issue is pending response from the issue author cloudformation Issues related to CloudFormation workflow labels Jan 16, 2024
@BBopanna
Copy link
Author

Thankyou - problem seems to be around large number of custom resources added in amplify cdk - https://docs.amplify.aws/react/build-a-backend/graphqlapi/modify-amplify-generated-resources/#place-appsync-resolvers-in-custom-named-stacks

Is there a way to break custom resources added via amplify cdk into multiple stacks ?

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Jan 17, 2024
@ykethan
Copy link
Member

ykethan commented Jan 17, 2024

@BBopanna , it is currently not supported to split the custom resource. From the number of resources provided on custom, the issue may be due to the number of resolvers on the GraphQL API.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Jan 17, 2024
@BBopanna
Copy link
Author

BBopanna commented Jan 18, 2024

Is there a way to create a new stack in the cdk part of amplify ?

This documentation talks about it when working entirely using cdk - https://docs.aws.amazon.com/cdk/v2/guide/stack_how_to_create_multiple_stacks.html

Is this possible in cdk part of amplify ?

Also use dependOn (https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-attribute-dependson.html) - may be ?

stack1.node.addDependency(stack2)

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Jan 18, 2024
@ykethan
Copy link
Member

ykethan commented Jan 18, 2024

@BBopanna tried creating nested and creating a dependOn with a new stack but i have not been able to split the resource.

Examples tried:

const nst = new NestedStack(this, "nstsk", {});
this.node.addDependency(nst);

class NestedStack extends cdk.NestedStack {
  constructor(scope: Construct, id: string, props?: cdk.NestedStackProps) {
    super(scope, id, props);

    // Define resources for the nested stack here
    new cdk.aws_s3.Bucket(this, "MyBucket");
  }
}

push ran into TemplateURL must be a supported URL.

also tried

this.node.addDependency(cdkStack1);

export class cdkStack1 extends cdk.Stack {
  constructor(
    scope: Construct,
    id: string,
    props?: cdk.StackProps,
    amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps
  ) {
    super(scope, id, props);
    /* Do not remove - Amplify CLI automatically injects the current deployment environment in this input parameter */
    new cdk.CfnParameter(this, "env", {
      type: "String",
      description: "Current Amplify CLI env name",
    });

    const amplifyProjectInfo = AmplifyHelpers.getProjectInfo();
    const sqsQueueResourceNamePrefix = `sqs-queue-stack1test`;
    const queue = new sqs.Queue(this, "sqs-queue-stack1", {
      queueName: `${sqsQueueResourceNamePrefix}-${cdk.Fn.ref("env")}`,
    });
  }
}

If the use case requires creating custom resources, I would suggest Amplify Gen 2 or using pure cdk with Amplify GraphQL API construct as an workaround.

@ykethan ykethan added pending-response Issue is pending response from the issue author custom-cdk Issues related to custom CDK resource functionality labels Jan 18, 2024
@BBopanna
Copy link
Author

Thankyou @ykethan for trying it out and sharing few more valuable resources - We are on Amplify Gen 1 - what are the possible ways we could go about now that you have mentioned that attempting to add new stack in amplify cdk is not working out ? Please advise.

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Jan 20, 2024
@ykethan
Copy link
Member

ykethan commented Jan 23, 2024

@BBopanna the workaround would be to limit the resources on amplify push, by removing some of the resources and push; then add them back in and push.
From then number of resources provided the push is likely failing on the 50+ GraphQL models as the custom resources are only 6. you could try consolidating the models or temporarily remove some models and push.
additionally, you could try creating a pure cdk app to create the custom resources.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Jan 23, 2024
@BBopanna
Copy link
Author

Thankyou @ykethan, in light of the above road block and intent to break our app into smaller apps/services some questions

  1. Can we have same Cognito for 2 different Amplify envs - with the intent of breaking the app into two amplify apps ?

  2. Can we migrate Amplify from Gen1 to Gen2? Please let us know any known limitations of services in Gen2.

  3. How to eject amplify project to CDK project? Current documentation is too trivial on the same - https://docs.amplify.aws/javascript/tools/cli/usage/export-to-cdk/ it really does not export everything, lot of refactoring!

  4. Can we export the DynamoDB table records of one amplify env and import those records to another amplify env - Production backup and restore? And Can we do the same for Cognito too - back up user credentials and restore ? OR can we link the same Cognito to the new env?

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Jan 29, 2024
@ykethan
Copy link
Member

ykethan commented Jan 29, 2024

@BBopanna Amplify Gen 1, does support importing existing auth resources. Refer to https://docs.amplify.aws/javascript/build-a-backend/auth/import-existing-resources/ providing this information.
Amplify Gen 2 is currently in developer preview and are exploring a migration guide for when the service is generally available.
For exporting and importing data you should be able to use the export to S3 and import from S3 functionality on DynamoDb or build a custom script. additionally, Amplify Gen 1 provides importing existing DynamoDB tables: https://docs.amplify.aws/javascript/build-a-backend/storage/import/
Unfortunately, i dont believe Cognito provides a export functionality but does provide a import functionality. refer to https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-using-import-tool.html for additional information.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Jan 29, 2024
@BBopanna
Copy link
Author

BBopanna commented Feb 2, 2024

Thankyou @ykethan .

Why does commenting the resources in custom resources and pushing and the uncommenting and pushing working if we have truly hit a "Limit" problem. Limit should be a limit irrespective of commenting and uncommenting - What is truly happening here ?

Also how can we use entities defined in .graphql of Gen1 in Gen2 (since docs talk about defining entity in code in Gen2) ? hope folks at Amplify dont expect Gen1 clients to refactor/rewrite entirely ?

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Feb 2, 2024
@ykethan
Copy link
Member

ykethan commented Feb 2, 2024

@BBopanna
Commenting and un-commenting model definitions in your GraphQL schema toggle creation/deletion of underlying resources such as DynamoDB tables and AppSync resolvers for each of the operations. In some cases, auth resolvers are reused to reduce the amount of resources deployed, however this is not necessarily the case with the remaining pipeline resolvers and can inflate the stacks resources beyond the supported limit.

At this time, CloudFormation has a hard limitation of 2500 resources per nested stack and 500 resources per individual stack. Amplify created stacks are all under one root, nested stack is not fully adjustable at this time.
Complex GraphQL schema could be simplified to reduce the number of GraphQL resources in use e.g rewriting the schema to have less models. Using escape hatches like overrides and export may help to scale the application beyond the CLI generated architecture.

You may be able to explore AWS CDK/Amplify Gen 2 (currently in public preview) which allows for a more IaC design that permits more freedom. However, these resources are all still under one nested stack, too but we can create new stacks as needed to mitigate this.

@ykethan ykethan added the pending-response Issue is pending response from the issue author label Feb 2, 2024
@BBopanna
Copy link
Author

BBopanna commented Feb 4, 2024

thankyou @ykethan

@github-actions github-actions bot removed the pending-response Issue is pending response from the issue author label Feb 4, 2024
@ykethan
Copy link
Member

ykethan commented Feb 5, 2024

Closing the issue, feel free in reaching out to us again if you require any further assistance.

@ykethan ykethan closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2024
Copy link

github-actions bot commented Feb 5, 2024

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@MarlonJD
Copy link

I was getting same error, I have 63 models, 10 functions. I add some models to custom stacks with https://docs.amplify.aws/gen1/flutter/build-a-backend/graphqlapi/modify-amplify-generated-resources/#place-appsync-resolvers-in-custom-named-stacks. and pushed with amplify push --minify. Gen 1 is works perfect now.

But I couldn't found solution on Gen 2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cloudformation Issues related to CloudFormation workflow custom-cdk Issues related to custom CDK resource functionality pending-triage Issue is pending triage
Projects
None yet
Development

No branches or pull requests

3 participants