amplify-cli: CloudFormation cannot update a stack when a custom-named resource requires replacing when using @key
Can I use @key on an existing table with data?
Because when I add a @key field to my model I get:
CloudFormation cannot update a stack when a custom-named resource requires replacing.
and the CloudFormation is rolling back.
The table has over 2k items of data in it, so dropping the table is not a good option
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 15 (4 by maintainers)
Any news? This error still persists
When
@keydirective is used with out the name argument, GraphQL transformer treats it as a primary index. For an existing model which did not use any@keydirective, transformer would have already created the primary index.If you’re editing a model which is already pushed, I would recommend you give a name to your
@keydirective as updating the primary index in Dynamo DB is not supported@dylan-westbury I was able to get around this by removing the model from the graphql schema, pushing to delete the DDB table, and recreating with the
@keypresent, as well as a primary@keythat includes a sort key (without it, LSI creation fails with a message like “no range key”).This is due (in my case) to the directive creating a Local Secondary Index, which must be defined on table creation. In any case, this is not the way to enable functionality similar to a sql “ORDER BY” on the entire model.
The generated query demands a model id, and returns results that share that id, sorted by the sort key & condition given to the query. This is one of the times where the GraphQL Transform tricks you (or at least me!) into thinking you are dealing with a relational structure, when it is really not.