CloudConsole

Circular dependency between resources

Updated 16 November 2026 · How we write and check guides

Short answer

CloudFormation builds a dependency graph from every Ref, Fn::GetAtt, Fn::Sub reference and DependsOn. If resources depend on each other in a loop, it cannot decide what to create first and rejects the template. Break the loop by splitting one side into a separate resource (such as a standalone security group rule or permission), building an ARN from a known name instead of referencing the resource, or removing an unnecessary DependsOn.

Other common loops, in 3 steps: 1. Unneeded DependsOn; 2. Outputs or tags; 3. Cross-stack cycles
The diagnosis and fix steps from this page, in the order to try them; commands and details are below.

Reading the error

Circular dependency between resources: [UploadsBucket, ProcessFunction,
ProcessFunctionPermission, ProcessFunctionRole]

The list contains every resource in the cycle, not just the two at fault, so draw the arrows: for each listed resource, note which others it references. The loop usually involves an implicit reference you did not think of, such as a bucket ARN inside an IAM policy or a security group ID inside another group's inline rules.

The S3 notification loop

The most common cycle: the bucket's NotificationConfiguration needs the Lambda function; the Lambda permission needs the bucket's ARN; the bucket cannot be created until the permission exists (S3 validates the notification target). Break it by naming the bucket and building its ARN by hand, so the permission no longer references the bucket resource:

Parameters:
  BucketName:
    Type: String
Resources:
  ProcessFunctionPermission:
    Type: AWS::Lambda::Permission
    Properties:
      FunctionName: !Ref ProcessFunction
      Action: lambda:InvokeFunction
      Principal: s3.amazonaws.com
      SourceAccount: !Ref AWS::AccountId
      SourceArn: !Sub arn:${AWS::Partition}:s3:::${BucketName}
  UploadsBucket:
    Type: AWS::S3::Bucket
    DependsOn: ProcessFunctionPermission
    Properties:
      BucketName: !Ref BucketName
      NotificationConfiguration:
        LambdaConfigurations:
          - Event: s3:ObjectCreated:*
            Function: !GetAtt ProcessFunction.Arn

The same trick applies when the function's IAM role policy references the bucket: use the constructed ARN there too.

Security groups that reference each other

Two groups whose inline SecurityGroupIngress rules each name the other form a cycle. Create the groups without cross-references, then add the rules as separate resources:

  AppToDbIngress:
    Type: AWS::EC2::SecurityGroupIngress
    Properties:
      GroupId: !Ref DbSecurityGroup
      IpProtocol: tcp
      FromPort: 5432
      ToPort: 5432
      SourceSecurityGroupId: !Ref AppSecurityGroup

The same pattern (a separate attachment resource) breaks loops with IAM policies (AWS::IAM::Policy or AWS::IAM::RolePolicy instead of inline policies), bucket policies and many association resources.

Other common loops

  • Unneeded DependsOn added "to be safe" that points back up the chain. Remove it; implicit references already order most resources.
  • Outputs or tags do not create cycles, but a Fn::Sub string that mentions ${SomeResource} does create a dependency, even inside a policy document or user data.
  • Cross-stack cycles: two stacks importing each other's exports cannot be deployed. Move the shared resource into one stack or into a third.

Tooling

cfn-lint reports circular dependencies before you deploy, and CloudFormation itself rejects them at validation time, so no resources are created. In CDK, cycles often appear when a construct in one stack grants permissions on a resource in another; moving the grant or the resource into the same stack usually resolves it.

Questions

How do I fix a circular dependency between an S3 bucket and a Lambda function?

Name the bucket, build its ARN with Fn::Sub for the Lambda permission and IAM policy instead of referencing the bucket resource, and make the bucket DependsOn the permission.

Does DependsOn cause circular dependencies?

It can. DependsOn adds an explicit edge to the graph; combined with implicit Ref and GetAtt edges, it can close a loop. Remove any DependsOn that is not needed.

Will CloudFormation create any resources if there is a circular dependency?

No. The template is rejected during validation before any resource is created.

CloudConsole CodePipeline screen on a phone, for following up on Circular dependency between resources away from your desk
When this happens away from your desk

Circular dependencies are caught before anything changes, so they never page anyone. CloudConsole, a phone app for AWS, is built for the situations that do: alarms, logs and resource state on your phone while a fix works its way through the pipeline.

Did it start after a deploy? What changed? on the app’s alarm screen lists the deploys and configuration changes from the hour before the alarm fired.

About the app → · Download on the App Store

Sources