The behaviour of CloudFormation DependsOn is inconsistent given the same template

0

Reproducible Repository: https://github.com/Willis0826/cdk-cr-dependency-issue

I expect two CloudFormation stacks with the same CloudFormation template should always have the same behaviour. However, I notice there is a case CloudFormation will ignore the DependsOn attribute while performing stack deletion.

The case is, we create EIP and NLB via CDK first, then we create a custom resource with the DependsOn attribute via CDK. After the creation was completed, we will get the CloudFormation template as follows:

{
  "Resources": {
    "loadbalancer": {
      ...
      "Properties": {
        "SubnetMappings": [
          {
            "AllocationId": {
              "Fn::GetAtt": [
                "eipA",
                "AllocationId"
              ]
            }
            ...
          }
          ...
        }
      }
      "DependsOn": [
        "customresourceA",
        ...
      ]
    }
    "eipA": {
      ...
    }
    "customresourceA": {
      ...
      "Properties": {
        "ElasticIp": {
          "Ref": "eipA"
        }
      }
    }
    ...
  }
}

Based on this template, I assume the dependency is as follows:

  • loadbalancer depends on eipA and customresourceA
  • customresourceA depends on eipA

The desired order of stack creation should be:

  • eipA -> customresourceA -> loadbalancer

The desired order of stack deletion should be:

  • loadbalancer -> customresourceA -> eipA

However, when I performed stack deletion, CloudFormation deleted loadbalancer and customresourceA at the same time. It seems like CloudFormation ignored the DependsOn field of loadbalancer resource.

inconsistent

But, if I create EIP, NLB and custom resource at once, the CloudFormation can perform deletion in the correct order.

consistent

willis
질문됨 일 년 전390회 조회
2개 답변
0

Woof, any feedback is welcome

willis
답변함 5달 전
0

I am still alive and curious about this! Give me a shout if you are willing to accept this challenge. 🍺

willis
답변함 16일 전

로그인하지 않았습니다. 로그인해야 답변을 게시할 수 있습니다.

좋은 답변은 질문에 명확하게 답하고 건설적인 피드백을 제공하며 질문자의 전문적인 성장을 장려합니다.

질문 답변하기에 대한 가이드라인

관련 콘텐츠