amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

Ability to create more than 25 @models at once

Open trupa7 opened this issue 7 years ago • 28 comments

As I added more table to my schema I am getting this error and some time I get error related to maximum number of tables that can be created simultaneously. It's deleted all my previously created tables and data in that tables.

Q1. can we Increase limits for dynamodb to create tables or indexes simultaneously?

Q2. is there any way we can prevent deletion of tables while got in to this error?

Q3 . Is it possible that it will create limited tables at time so it will not exceed limits

trupa7 avatar Oct 15 '19 18:10 trupa7

I have 43 tables which includes (m:n relationships tables)

trupa7 avatar Oct 15 '19 19:10 trupa7

@trupa7

  1. Looks like a DynamoDB soft limit that can be raised upon request, try opening a ticket with Support as demonstrated here.
  2. Not yet. Agreed, it would be nice if the CLI defaulted to Retain for each table provisioned under the API and Storage categories.
  3. I think the only way to do this in CloudFormation is to force resources to create in a certain order, either by using DependsOn or nested stacks. I think (3) would require a significant refactor of the transformer and the architecture of the generated root API stack.

jkeys-ecg-nmsu avatar Oct 15 '19 23:10 jkeys-ecg-nmsu

@trupa7 btw if you hit up support right now (within 24 hours I believe) they will be able to restore your tables.

@yuth @kaustavghosh06 I know you all don't release roadmaps but it's hard to see how the API category will be useful for much more than prototyping if a bad push can drop all your production tables, and then potentially drop your AppSync API.

jkeys-ecg-nmsu avatar Oct 15 '19 23:10 jkeys-ecg-nmsu

@trupa7 I'm not clear as to how all your previously created tables were deleted. Could you please explain more as to the steps to reproduce this behavior in deletion of tables with data?

kaustavghosh06 avatar Oct 15 '19 23:10 kaustavghosh06

@kaustavghosh06 as I added new schemas which have relationship with old tables . If creation of new tables will failed it deletes all previously created tables which have relationship with new tables. Reason of failing is same subscriber limit exceeded.

You have exceeded the maximum number of indexed tables that can be created simultaneously

trupa7 avatar Oct 16 '19 17:10 trupa7

@kaustavghosh06 so ,is that because of the relationships as I add more m:n relationship tables with new schemas it will add new secondary indexes to the related tables.

is this can be a cause??

API-Specific Limits CreateTable/UpdateTable/DeleteTable

The only exception is when you are creating a table with one or more secondary indexes. You can have up to 25 such requests running at a time.

https://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Limits.html#limits-api

trupa7 avatar Oct 16 '19 17:10 trupa7

@trupa7 Could you provide us with a before/after graphql annotated schema so that we can reproduce this behavior? Deleting of the tables isn't the intended behavior, but would like to reproduce and fix it.

kaustavghosh06 avatar Oct 17 '19 18:10 kaustavghosh06

@kaustavghosh06 If OP has a 43 model schema I doubt he'd be willing to share that publicly. Could you provide him an email to send the schemas?

@trupa7 maybe you're applications is extremely complex and needs that many models, but is there no way to denormalize your schema, remove nested models, etc. and overload models with indexes with the @key directive to support access patterns?

The only reason I can think of to have that many Dynamo tables is that you're doing it because currently the GQL Transformer-generated indexes project all attributes (#2577), and this is a way around that without having to fiddle with the Amp-gen stacks to not project all attributes on all indexes.

jkeys-ecg-nmsu avatar Oct 18 '19 03:10 jkeys-ecg-nmsu

@kaustavghosh06 : I unable to share it because of our company's policy. I can try to make dummy schemas to reproduce this error.

trupa7 avatar Oct 21 '19 17:10 trupa7

@kaustavghosh06 If OP has a 43 model schema I doubt he'd be willing to share that publicly. Could you provide him an email to send the schemas?

@trupa7 maybe you're applications is extremely complex and needs that many models, but is there no way to denormalize your schema, remove nested models, etc. and overload models with indexes with the @key directive to support access patterns?

The only reason I can think of to have that many Dynamo tables is that you're doing it because currently the GQL Transformer-generated indexes project all attributes (#2577), and this is a way around that without having to fiddle with the Amp-gen stacks to not project all attributes on all indexes.

@jkeys-ecg-nmsu : I can try to denormalize some schema but as we will add more models in future I am afraid to get same errors. It's not just models but also we have tables which contains m:n relationships as amplify don't support m:n relationship directly.

trupa7 avatar Oct 21 '19 17:10 trupa7

Hi Everyone,

Ahsan here from Rapticore. Thank you for your support, it is really appreciated. If it is possible lets get on a call and we will show you our schema, what we are doing and what errors we are seeing. If you still need the actual schema after that we can work something out. Again we appreciate your support. We are looking forward to making Amplify and AppSync core part of our application architecture.

Thanks,

Ahsan Mir

ahsansmir avatar Oct 21 '19 18:10 ahsansmir

@ahsansmir I'm just trying to be a Good Samaritan by trying to help close issues, I am not an Amplify developer.

@kaustavghosh06 can you provide @ahsansmir @trupa7 with a private email to send the schema?

jkeys-ecg-nmsu avatar Oct 23 '19 01:10 jkeys-ecg-nmsu

@kaustavghosh06 : I created dummy schema to reproduce this error. If you can use it and reproduce this error. Please guide us if we are doing something wrong or is this because it's hitting the limit.

https://github.com/trupa7/amplify-data/tree/master/schema

thanks

trupa7 avatar Oct 29 '19 23:10 trupa7

@trupa7 @ahsansmir Those repeating sequences within distinct field names (e.g. search for "zqd", "RFUd", "FFd") might be more revealing than you had intended. It looks to me like you posted a fun exercise in cryptography to see how much information can be reverse engineered from your obfuscated schema. Something to consider...

Actually it was more like a bioinformatics + crypto puzzle before you removed it, where you would try to iteratively find higher k-mers until you can't find any more, then collapse that into an alphabet, then try to assign meaning. Could I get a security consulting fee btw? :P

jkeys-ecg-nmsu avatar Oct 30 '19 00:10 jkeys-ecg-nmsu

@trupa7 @ahsansmir @kaustavghosh06 that being said please send that obfuscated (or an actual dummy schema that replicates the behavior) to the Amplify team. For what it's worth I think you can omit almost all the fields since the error is related to creating tables concurrently (then deleting them), so that should help with intellectual property concerns.

jkeys-ecg-nmsu avatar Oct 30 '19 04:10 jkeys-ecg-nmsu

@trupa7 Did you get a chance to talk to AWS support and increase the soft limit for DDB table creations as mentioned by @jkeys-ecg-nmsu?

kaustavghosh06 avatar Oct 31 '19 18:10 kaustavghosh06

@trupa7 try submitting a ticket to AWS Support to raise the soft limit and see if your issue re-occurs with your sample schema, please.

jkeys-ecg-nmsu avatar Nov 02 '19 02:11 jkeys-ecg-nmsu

Hi @kaustavghosh06 - I work on the same team as @ahsansmir and @trupa7 . We requested limit increase to the maximum allowed concurrent DynamoDB GSI limit - 100.

The limit was increased, and AWS Support said:

I've been working closely with our DynamoDB team on getting your request fulfilled and they already stated that it will be fulfilled in the next 2-3 days as long as you acknowledge that this may not fix your bottle neck and you could hit the new limit again.

They've also stated that we would not be able to further increase the limit after 100 in-flight-tables, as that's the maximum it can be increased.

"We can increase your limit to a degree, but note that you might not always be able to achieve the full number of concurrent control plane operations, depending on which combination of operations you are doing at once. If the table or index specifications are complex, such as a CreateTable requests with several Secondary Indexes, especially when each index has a "Projection" with many “NonKeyAttributes”, DynamoDB might temporarily reduce the number of concurrent operations.

With our schema, and with the new limit increase, we are still receiving the same error.

I attempted a workaround, where I modified the generated CloudFormation stack (amplify/backend/api/<apiname>/build/cloudformation-template.json) to sequentially create each nested stack, by adding each nested stack resource reference to the next stack's DependsOn attribute.

Here's a snippet from the CloudFormation stack showing the DependsOn changes.

{ "Organization": { "Type": "AWS::CloudFormation::Stack", "Properties": {}, "DependsOn": [ "GraphQLSchema", "NoneDataSource" ] }, "Application": { "Type": "AWS::CloudFormation::Stack", "Properties": {}, "DependsOn": [ "GraphQLSchema", "NoneDataSource", "Organization" ] }, "Group": { "Type": "AWS::CloudFormation::Stack", "Properties": {}, "DependsOn": [ "GraphQLSchema", "NoneDataSource", "Application" ] } }

I was able to successfully deploy the CloudFormation stack this way, however the Amplify CLI stopped working at this point - amplify status reports No Changes, and any attempt to amplify env pull or amplify env pull --restore or amplify push does not have any effect.

rrrix avatar Nov 17 '19 16:11 rrrix

Hi Amplify team,

I'm on the same team as @ahsansmir and @trupa7 (the OP of this issue)

Unfortunately, we have a new issue. Should I create a new Issue in GitHub for this?

The autogenerated JSON CloudFormation stack is too large - 811KB - and exceeds the allowed size in of 460KB.

CREATE_FAILED apiissue2584 AWS::CloudFormation::Stack Mon Nov 18 2019 09:42:09 GMT-0800 (Pacific Standard Time) Template may not exceed 460800 bytes in size.

I was attempting to add @auth directives to all of our types, so we can use a combination of Cognito, API Keys and IAM to access our AppSync API.

Just for fun, I tried cfn-flip to see what the YAML equivalent would be, and that is FAR smaller at 271KB, very much under the 460KB limit.

-rw-r--r-- 1 user staff 811K Nov 18 09:37 cloudformation-template.json -rw-r--r-- 1 user staff 271K Nov 18 09:44 cloudformation-template.yaml

I've re-obfuscated the schema that @trupa7 originally posted, and removed all the unnecessary String/Enum/AWSDate*/Boolean/etc. fields from all the types.

This verison (with @auth directives) Produces a CloudFormation template which is too large - cannot deploy: https://gist.github.com/rrrix/e7874ba46f9911604aec1eb1554ba07d

This version (without @auth) causes CloudFormation to deploy too many DynamoDB tables concurrently which results in a LimitExceededException and the entire API stack fails: https://gist.github.com/rrrix/09ade36345c988b6be581063aa49f219

I just reproduced it again this morning, even with the limit increase.

Subscriber limit exceeded: You have exceeded the maximum number of indexed tables that can be created simultaneously (Service: AmazonDynamoDBv2; Status Code: 400; Error Code: LimitExceededException;

rrrix avatar Nov 18 '19 18:11 rrrix

@trupa7 @kaustavghosh06 I don't think this is a priority for the Amplify team because that many tables is considered somewhat of an abuse of NoSQL. You should try to denormalize your schema and drop as many models as possible. For instance, for 1-to-1 connection field that is rarely updated or read-only, you could make it a simple AWSJSON blob instead of a model connection without much disruption. But if you need to frequently update that field, leave it as its own model. At least, that's my understanding of the suggested usage of the key and connection directives.

jkeys-ecg-nmsu avatar Dec 03 '19 01:12 jkeys-ecg-nmsu