Skip to content

Commit 1eced2c

Browse files
authored
chore: add error mappings and resolutions for circular dependency failures (#2342)
1 parent f193105 commit 1eced2c

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

.changeset/early-dodos-pull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@aws-amplify/backend-deployer': patch
3+
---
4+
5+
add mapping for circular dependency failures with resolution

packages/backend-deployer/src/cdk_error_mapper.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,6 +665,20 @@ npm error enoent`,
665665
errorName: 'InvalidOrCannotAssumeRoleError',
666666
expectedDownstreamErrorMessage: undefined,
667667
},
668+
{
669+
errorMessage: `some-stack failed: ValidationError: Circular dependency between resources: [storage1, data1, function1] `,
670+
expectedTopLevelErrorMessage:
671+
'The CloudFormation deployment failed due to circular dependency found between nested stacks [storage1, data1, function1]',
672+
errorName: 'CloudformationStackCircularDependencyError',
673+
expectedDownstreamErrorMessage: undefined,
674+
},
675+
{
676+
errorMessage: `The stack named named-stack failed to deploy: UPDATE_ROLLBACK_COMPLETE: Circular dependency between resources: [resource1, resource2] `,
677+
expectedTopLevelErrorMessage:
678+
'The CloudFormation deployment failed due to circular dependency found between resources [resource1, resource2] in a single stack',
679+
errorName: 'CloudformationResourceCircularDependencyError',
680+
expectedDownstreamErrorMessage: undefined,
681+
},
668682
];
669683

670684
void describe('invokeCDKCommand', { concurrency: 1 }, () => {

packages/backend-deployer/src/cdk_error_mapper.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,32 @@ export class CdkErrorMapper {
486486
errorName: 'BackendSynthError',
487487
classification: 'ERROR',
488488
},
489+
{
490+
// This error pattern is observed when circular dependency is between stacks but not resources in a stack
491+
errorRegex:
492+
/ValidationError: Circular dependency between resources: \[(?<resources>.*)\]/,
493+
humanReadableErrorMessage:
494+
'The CloudFormation deployment failed due to circular dependency found between nested stacks [{resources}]',
495+
resolutionMessage: `If you are using functions then you can assign them to existing nested stacks that are dependent on functions or functions depend on them, for example:
496+
1. If your function is defined as auth triggers, you should assign this function to auth stack.
497+
2. If your function is used as data resolver or calls data API, you should assign this function to data stack.
498+
To assign a function to a different stack, use the property 'resourceGroupName' in the defineFunction call and choose auth, data or any custom stack.
499+
500+
If your circular dependency issue is not resolved with this workaround, please create an issue here https://github.com/aws-amplify/amplify-backend/issues/new/choose
501+
`,
502+
errorName: 'CloudformationStackCircularDependencyError',
503+
classification: 'ERROR',
504+
},
505+
{
506+
// This error pattern is observed when circular dependency is between resources in a single stack, i.e. ValidationError is absent from the error message
507+
errorRegex:
508+
/(?<!ValidationError: )Circular dependency between resources: \[(?<resources>.*)\]/,
509+
humanReadableErrorMessage:
510+
'The CloudFormation deployment failed due to circular dependency found between resources [{resources}] in a single stack',
511+
resolutionMessage: `If you are creating custom stacks or adding new CDK resources to amplify stacks, ensure that there are no cyclic dependencies. For more details see: https://aws.amazon.com/blogs/infrastructure-and-automation/handling-circular-dependency-errors-in-aws-cloudformation/`,
512+
errorName: 'CloudformationResourceCircularDependencyError',
513+
classification: 'ERROR',
514+
},
489515
{
490516
errorRegex:
491517
/(?<stackName>amplify-[a-z0-9-]+)(.*) failed: ValidationError: Stack:(.*) is in (?<state>.*) state and can not be updated/,
@@ -523,6 +549,8 @@ export type CDKDeploymentError =
523549
| 'CDKResolveAWSAccountError'
524550
| 'CDKVersionMismatchError'
525551
| 'CFNUpdateNotSupportedError'
552+
| 'CloudformationResourceCircularDependencyError'
553+
| 'CloudformationStackCircularDependencyError'
526554
| 'CloudFormationDeletionError'
527555
| 'CloudFormationDeploymentError'
528556
| 'CommonNPMError'

0 commit comments

Comments
 (0)