Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the CloudFormation deployment failed due to circular dependency found between nested stacks #2446

Open
cookiejest opened this issue Jan 23, 2025 · 1 comment
Labels
function Issue pertaining to Amplify Function pending-response Issue is pending response from author pending-triage Incoming issues that need categorization

Comments

@cookiejest
Copy link

cookiejest commented Jan 23, 2025

Environment information

the CloudFormation deployment failed due to circular dependency found between nested stacks

I am trying the AI functionality and want to fire a custom (python) lambda function when a record is added to a 'Run' model via an event.

Latest release amplify -

"aws-amplify": "^6.12.1",
"@aws-amplify/backend": "^1.13.0",
"@aws-amplify/backend-cli": "^1.4.7",

Describe the bug

As reported in the console:

The CloudFormation deployment failed due to circular dependency found between nested stacks [storage0EC3F24A, auth179371D7, data7552DF31, function1351588B]
Resolution: 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:
1. If your function is defined as auth triggers, you should assign this function to auth stack.
2. If your function is used as data resolver or calls data API, you should assign this function to data stack.
To assign a function to a different stack, use the property 'resourceGroupName' in the defineFunction call and choose auth, data or any custom stack.

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

Reproduction steps

I created a custom lambda function in python. Tried to assign it to a listner event. This triggers the error. The suggested solution in the error does not work as resourceGroupName is not a valid property of on the custom lambda function.

const runEventSource = new DynamoEventSource(backend.data.resources.tables["Run"], {
  startingPosition: StartingPosition.LATEST,
  batchSize: 1
});


backend.sayHelloFunctionHandler.resources.lambda.addEventSource(runEventSource);

Custom python function definition as following the docs:

https://docs.amplify.aws/react/build-a-backend/functions/custom-functions/#:~:text=for%20your%20functions.-,Python,say%2Dhello%2Fresource.ts

import { execSync } from "node:child_process";
import * as path from "node:path";
import { fileURLToPath } from "node:url";
import { defineFunction } from "@aws-amplify/backend";
import { DockerImage, Duration } from "aws-cdk-lib";
import { Code, Function, Runtime } from "aws-cdk-lib/aws-lambda";

const functionDir = path.dirname(fileURLToPath(import.meta.url));

export const sayHelloFunctionHandler = defineFunction(
  (scope) =>
    new Function(scope, "say-hello", {
      handler: "index.handler",
      runtime: Runtime.PYTHON_3_9, // or any other python version
      timeout: Duration.seconds(20), //  default is 3 seconds
      code: Code.fromAsset(functionDir, {
        bundling: {
          image: DockerImage.fromRegistry("dummy"), // replace with desired image from AWS ECR Public Gallery
          local: {
            tryBundle(outputDir: string) {
              execSync(
                `python3 -m pip install -r ${path.join(functionDir, "requirements.txt")} -t ${path.join(outputDir)} --platform manylinux2014_x86_64 --only-binary=:all:`
              );
              execSync(`cp -r ${functionDir}/* ${path.join(outputDir)}`);
              return true;
            },
          },
        },
      }),
    })
);

@cookiejest cookiejest added the pending-triage Incoming issues that need categorization label Jan 23, 2025
@ykethan
Copy link
Member

ykethan commented Jan 23, 2025

Hey @cookiejest, thank you for reaching out. The resourceGroupName property is currently supported on a custom defineFunction as second argument.

for example:


export const sayHelloFunctionHandler = defineFunction(
  (scope) =>
    new Function(scope, "say-hello", {
      handler: "index.handler",
      runtime: Runtime.PYTHON_3_9, // or any other python version
      timeout: Duration.seconds(20), //  default is 3 seconds
      code: Code.fromAsset(functionDir, {
        bundling: {
          image: DockerImage.fromRegistry("dummy"), // replace with desired image from AWS ECR Public Gallery
          local: {
            tryBundle(outputDir: string) {
              execSync(
                `python3 -m pip install -r ${path.join(
                  functionDir,
                  "requirements.txt"
                )} -t ${path.join(
                  outputDir
                )} --platform manylinux2014_x86_64 --only-binary=:all:`
              );
              execSync(`cp -r ${functionDir}/* ${path.join(outputDir)}`);
              return true;
            },
          },
        },
      }),
    }),
  {
    resourceGroupName: "auth", // groups function with auth
  }
);

@ykethan ykethan added function Issue pertaining to Amplify Function pending-response Issue is pending response from author labels Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
function Issue pertaining to Amplify Function pending-response Issue is pending response from author pending-triage Incoming issues that need categorization
Projects
None yet
Development

No branches or pull requests

2 participants