From f1b424e969003b9d6013181dde4be7558c63ca80 Mon Sep 17 00:00:00 2001 From: Praveen Gupta Date: Wed, 18 Dec 2024 18:06:58 +0100 Subject: [PATCH 1/9] chore: add troubleshooting for circular dependency errors in backend --- src/directory/directory.mjs | 3 + .../circular-dependency/index.mdx | 56 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx diff --git a/src/directory/directory.mjs b/src/directory/directory.mjs index 269af6f34ad..7e475d080a3 100644 --- a/src/directory/directory.mjs +++ b/src/directory/directory.mjs @@ -722,6 +722,9 @@ export const directory = { }, { path: 'src/pages/[platform]/build-a-backend/troubleshooting/cannot-find-module-amplify-env/index.mdx' + }, + { + path: 'src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx' } ] } diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx new file mode 100644 index 00000000000..a2927d28273 --- /dev/null +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -0,0 +1,56 @@ +import { getCustomStaticPath } from '@/utils/getCustomStaticPath'; + +export const meta = { + title: 'Troubleshoot circular dependency issues', + description: 'Addressing deployment failures caused by circular dependencies', + platforms: [ + 'angular', + 'javascript', + 'nextjs', + 'react', + 'react-native', + 'vue' + ] +}; + +export function getStaticPaths() { + return getCustomStaticPath(meta.platforms); +} + +export function getStaticProps(context) { + return { + props: { + meta + } + }; +} + +When deploying a Amplify Gen 2 app, you may encounter the error message `The CloudFormation deployment failed due to circular dependency` in your backend build on Amplify Console or while running a sandbox. This error can occur because of circular dependencies between cloudformation nested stacks or between resources in a single cloudformation stack. + +## Circular dependency error between nested stacks + +If you see this error "The CloudFormation deployment failed due to circular dependency found between nested stacks [data1234ABCD, function6789XYZ]", it means that the nested stack for data and the nested stack for function have circular dependencies. E.g. if you are using the function as a query handler, but the function also needs access to the data (or AppSync) API, you might run into this issue. To resolve, assign this function to the data stack + +```ts title="function.ts" +export const queryFunction = defineFunction({ + name: 'myFunction', + entry: '../handler.ts', + resourceGroupName: 'data', +}); +``` + +Similarly, if you are using your function as an auth trigger, you can assign your function to the auth stack to break the circular dependency. + +```ts title="function.ts" +export const preSignUpTrigger = defineFunction({ + name: 'myFunction', + entry: '../handler.ts', + resourceGroupName: 'auth', +}); +``` + +If you are unable to resolve this error using function's `resourceGroupName` property, please create an issue [here](https://github.com/aws-amplify/amplify-backend/issues/new/choose) + +## Circular dependency error between resources in the same stack + +If you see this error "The CloudFormation deployment failed due to circular dependency found between resources [resource1, resource2] in a single stack", that means the resources themselves have a circular dependency in the same stack. For handling such errors, see https://aws.amazon.com/blogs/infrastructure-and-automation/handling-circular-dependency-errors-in-aws-cloudformation/ From 0174d708d1cb67ec65620fb7052eb304b8342bfa Mon Sep 17 00:00:00 2001 From: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:52:19 +0100 Subject: [PATCH 2/9] Update src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx Co-authored-by: Kamil Sobol --- .../troubleshooting/circular-dependency/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx index a2927d28273..3ad106b3af5 100644 --- a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -25,7 +25,7 @@ export function getStaticProps(context) { }; } -When deploying a Amplify Gen 2 app, you may encounter the error message `The CloudFormation deployment failed due to circular dependency` in your backend build on Amplify Console or while running a sandbox. This error can occur because of circular dependencies between cloudformation nested stacks or between resources in a single cloudformation stack. +When deploying a Amplify Gen 2 app, you may encounter the error message `The CloudFormation deployment failed due to circular dependency` in your backend build on Amplify Console or while running a sandbox. This error can occur because of circular dependencies between CloudFormation nested stacks or between resources in a single CloudFormation stack. ## Circular dependency error between nested stacks From 04932242a0e4750b84b0fbf873ddedeaa9db105b Mon Sep 17 00:00:00 2001 From: Praveen Gupta Date: Wed, 18 Dec 2024 21:22:12 +0100 Subject: [PATCH 3/9] Add custom stack example --- .../troubleshooting/circular-dependency/index.mdx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx index 3ad106b3af5..849b7c421d9 100644 --- a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -48,9 +48,18 @@ export const preSignUpTrigger = defineFunction({ resourceGroupName: 'auth', }); ``` - If you are unable to resolve this error using function's `resourceGroupName` property, please create an issue [here](https://github.com/aws-amplify/amplify-backend/issues/new/choose) +### Circular dependency error with with a custom stack + +If you are creating cdk resources and assigning them to a CustomStack, you might also run into this issue. Your error message would look like "The CloudFormation deployment failed due to circular dependency found between nested stacks [storage1234ABCD, auth5678XYZ, **MYCustomStack0123AB**] + +To resolve this, try creating your resources in the same stack as the resources you are trying to interact with. For example, if a custom resource such as `sqs` needs to interact with the s3 resource created by `defineStorage`, you can create that `sqs` resource in the stack created by Amplify. You can reference the existing Amplify created stack like + +```ts title="backend.ts" +const queue = new sqs.Queue(backend.storage.stack, 'MyCustomQueue'); +``` + ## Circular dependency error between resources in the same stack If you see this error "The CloudFormation deployment failed due to circular dependency found between resources [resource1, resource2] in a single stack", that means the resources themselves have a circular dependency in the same stack. For handling such errors, see https://aws.amazon.com/blogs/infrastructure-and-automation/handling-circular-dependency-errors-in-aws-cloudformation/ From 1ad8cdde9399f6776f25a9712fedec6cf59c8036 Mon Sep 17 00:00:00 2001 From: Praveen Gupta Date: Wed, 18 Dec 2024 21:34:21 +0100 Subject: [PATCH 4/9] PR updates --- .../troubleshooting/circular-dependency/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx index 849b7c421d9..5c647974e1d 100644 --- a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -52,7 +52,7 @@ If you are unable to resolve this error using function's `resourceGroupName` pro ### Circular dependency error with with a custom stack -If you are creating cdk resources and assigning them to a CustomStack, you might also run into this issue. Your error message would look like "The CloudFormation deployment failed due to circular dependency found between nested stacks [storage1234ABCD, auth5678XYZ, **MYCustomStack0123AB**] +If you are creating cdk resources and assigning them to a custom stack, you might also run into this issue. Your error message would look like "The CloudFormation deployment failed due to circular dependency found between nested stacks [storage1234ABCD, auth5678XYZ, **MYCustomStack0123AB**]" To resolve this, try creating your resources in the same stack as the resources you are trying to interact with. For example, if a custom resource such as `sqs` needs to interact with the s3 resource created by `defineStorage`, you can create that `sqs` resource in the stack created by Amplify. You can reference the existing Amplify created stack like From 20d9a42f47b0b5232d860ef01554ef37a9ee37e2 Mon Sep 17 00:00:00 2001 From: Praveen Gupta Date: Wed, 18 Dec 2024 21:36:52 +0100 Subject: [PATCH 5/9] PR updates --- .../troubleshooting/circular-dependency/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx index 5c647974e1d..dabca11cb4d 100644 --- a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -25,11 +25,11 @@ export function getStaticProps(context) { }; } -When deploying a Amplify Gen 2 app, you may encounter the error message `The CloudFormation deployment failed due to circular dependency` in your backend build on Amplify Console or while running a sandbox. This error can occur because of circular dependencies between CloudFormation nested stacks or between resources in a single CloudFormation stack. +When deploying a Amplify Gen 2 app, you may encounter the error message `The CloudFormation deployment failed due to circular dependency` in your backend build on Amplify Console or while running a sandbox. This error can occur due to circular dependencies between CloudFormation nested stacks or between resources in a single CloudFormation stack. ## Circular dependency error between nested stacks -If you see this error "The CloudFormation deployment failed due to circular dependency found between nested stacks [data1234ABCD, function6789XYZ]", it means that the nested stack for data and the nested stack for function have circular dependencies. E.g. if you are using the function as a query handler, but the function also needs access to the data (or AppSync) API, you might run into this issue. To resolve, assign this function to the data stack +If you see this error "The CloudFormation deployment failed due to circular dependency found between nested stacks [data1234ABCD, function6789XYZ]", it means that the nested stack for `data` and the nested stack for `function` have circular dependencies. E.g. if you are using the function as a query handler, but the function also needs access to the data (or `AppSync`) API, you might run into this issue. To resolve, assign this function to the `data` stack ```ts title="function.ts" export const queryFunction = defineFunction({ From 6f6f3bb592aa86b02b4485f60b33f42fce33304c Mon Sep 17 00:00:00 2001 From: Praveen Gupta Date: Wed, 18 Dec 2024 21:47:24 +0100 Subject: [PATCH 6/9] PR updates --- .../troubleshooting/circular-dependency/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx index dabca11cb4d..13b3210e303 100644 --- a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -29,7 +29,7 @@ When deploying a Amplify Gen 2 app, you may encounter the error message `The Clo ## Circular dependency error between nested stacks -If you see this error "The CloudFormation deployment failed due to circular dependency found between nested stacks [data1234ABCD, function6789XYZ]", it means that the nested stack for `data` and the nested stack for `function` have circular dependencies. E.g. if you are using the function as a query handler, but the function also needs access to the data (or `AppSync`) API, you might run into this issue. To resolve, assign this function to the `data` stack +If you see this error "The CloudFormation deployment failed due to circular dependency found between nested stacks [data1234ABCD, function6789XYZ]", it means that the nested stack for `data` and the nested stack for `function` have circular dependencies. E.g. if you are using the `function` as a query handler, but the `function` also needs access to the data (or `AppSync`) API, you might run into this issue. To resolve, group this `function` with other resources in the `data` stack ```ts title="function.ts" export const queryFunction = defineFunction({ @@ -39,7 +39,7 @@ export const queryFunction = defineFunction({ }); ``` -Similarly, if you are using your function as an auth trigger, you can assign your function to the auth stack to break the circular dependency. +Similarly, if you are using your `function` as an auth trigger, you can group your `function` with other resources in the `auth` stack to break the circular dependency. ```ts title="function.ts" export const preSignUpTrigger = defineFunction({ From 884dfc92d2a8f6f6efe4f550c45300727787fb93 Mon Sep 17 00:00:00 2001 From: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:17:59 +0100 Subject: [PATCH 7/9] Update src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx Co-authored-by: josef --- .../troubleshooting/circular-dependency/index.mdx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx index 13b3210e303..cabafc12ad7 100644 --- a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -31,7 +31,7 @@ When deploying a Amplify Gen 2 app, you may encounter the error message `The Clo If you see this error "The CloudFormation deployment failed due to circular dependency found between nested stacks [data1234ABCD, function6789XYZ]", it means that the nested stack for `data` and the nested stack for `function` have circular dependencies. E.g. if you are using the `function` as a query handler, but the `function` also needs access to the data (or `AppSync`) API, you might run into this issue. To resolve, group this `function` with other resources in the `data` stack -```ts title="function.ts" +```ts title="amplify/functions/my-function/resource.ts" export const queryFunction = defineFunction({ name: 'myFunction', entry: '../handler.ts', From ac37709ed5abb859fd0142455440e27ac14effe2 Mon Sep 17 00:00:00 2001 From: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:18:26 +0100 Subject: [PATCH 8/9] Update src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx Co-authored-by: josef --- .../troubleshooting/circular-dependency/index.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx index cabafc12ad7..85b87e6839f 100644 --- a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -34,7 +34,6 @@ If you see this error "The CloudFormation deployment failed due to circular depe ```ts title="amplify/functions/my-function/resource.ts" export const queryFunction = defineFunction({ name: 'myFunction', - entry: '../handler.ts', resourceGroupName: 'data', }); ``` From 889da3eaaf28849ab26c9bae781a15e6bf21f757 Mon Sep 17 00:00:00 2001 From: Amplifiyer <51211245+Amplifiyer@users.noreply.github.com> Date: Mon, 23 Dec 2024 19:19:35 +0100 Subject: [PATCH 9/9] Apply suggestions from code review Co-authored-by: josef --- .../circular-dependency/index.mdx | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx index 85b87e6839f..ab9c6d035e1 100644 --- a/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx +++ b/src/pages/[platform]/build-a-backend/troubleshooting/circular-dependency/index.mdx @@ -33,32 +33,31 @@ If you see this error "The CloudFormation deployment failed due to circular depe ```ts title="amplify/functions/my-function/resource.ts" export const queryFunction = defineFunction({ - name: 'myFunction', + name: 'query-function', resourceGroupName: 'data', }); ``` Similarly, if you are using your `function` as an auth trigger, you can group your `function` with other resources in the `auth` stack to break the circular dependency. -```ts title="function.ts" +```ts title="amplify/functions/my-function/resource.ts" export const preSignUpTrigger = defineFunction({ - name: 'myFunction', - entry: '../handler.ts', + name: 'pre-sign-up', resourceGroupName: 'auth', }); ``` -If you are unable to resolve this error using function's `resourceGroupName` property, please create an issue [here](https://github.com/aws-amplify/amplify-backend/issues/new/choose) +If you are unable to resolve this error using function's `resourceGroupName` property, please [create an issue on the GitHub repository for Amplify backend](https://github.com/aws-amplify/amplify-backend/issues/new/choose) ### Circular dependency error with with a custom stack -If you are creating cdk resources and assigning them to a custom stack, you might also run into this issue. Your error message would look like "The CloudFormation deployment failed due to circular dependency found between nested stacks [storage1234ABCD, auth5678XYZ, **MYCustomStack0123AB**]" +If you are creating resources using the [AWS Cloud Development Kit (AWS CDK)](https://aws.amazon.com/cdk/) and assigning them to a custom stack, you might also run into this issue. Your error message would look like "The CloudFormation deployment failed due to circular dependency found between nested stacks [storage1234ABCD, auth5678XYZ, **MYCustomStack0123AB**]" -To resolve this, try creating your resources in the same stack as the resources you are trying to interact with. For example, if a custom resource such as `sqs` needs to interact with the s3 resource created by `defineStorage`, you can create that `sqs` resource in the stack created by Amplify. You can reference the existing Amplify created stack like +To resolve this, try creating your resources in the same stack as the resources you are trying to interact with. For example, if a custom resource such as `sqs` needs to interact with the underlying Amazon S3 resource created by `defineStorage`, you can create that `sqs` resource in the stack created by Amplify. You can reference the existing Amplify created stack like -```ts title="backend.ts" +```ts title="amplify/backend.ts" const queue = new sqs.Queue(backend.storage.stack, 'MyCustomQueue'); ``` ## Circular dependency error between resources in the same stack -If you see this error "The CloudFormation deployment failed due to circular dependency found between resources [resource1, resource2] in a single stack", that means the resources themselves have a circular dependency in the same stack. For handling such errors, see https://aws.amazon.com/blogs/infrastructure-and-automation/handling-circular-dependency-errors-in-aws-cloudformation/ +If you see this error "The CloudFormation deployment failed due to circular dependency found between resources [resource1, resource2] in a single stack", that means the resources themselves have a circular dependency in the same stack. For handling such errors, review the [AWS Blog post for handling circular dependency errors](https://aws.amazon.com/blogs/infrastructure-and-automation/handling-circular-dependency-errors-in-aws-cloudformation/).