CloudFormation cnf-lint 已过时 "DependsOn"

CloudFormation cnf-lint Obsolete "DependsOn"

当 运行 cfn-lint 对以下代码我收到警告时

"MicroserviceSG": {
   "Type": "AWS::EC2::SecurityGroup",
⚠  "DependsOn": "MicroserviceLoadBalancerSGPrivate",
   "Properties": {
      "GroupName": {"Fn::Join": ["-", [{"Ref": "Name"}, {"Ref": "Env"}, "container-sg"]]},
      "GroupDescription": "HTTP",
         "VpcId": {"Ref": "VpcId"},
         "SecurityGroupIngress": [
            {
                "IpProtocol": "tcp",
                "FromPort": 80,
                "ToPort": 80,
                "SourceSecurityGroupId": { "Ref": "MicroserviceLoadBalancerSGPrivate" }
             }
           ]
        }
    },
W3005 Obsolete DependsOn on resource (MicroserviceLoadBalancerSGPrivate),
dependency already enforced by a "Ref" at 
Resources/MicroserviceSG/Properties/SecurityGroupIngress/0/SourceSecurityGroupId/Ref

这个警告有效吗?某些对象引用是否执行隐式依赖检查?

是的,警告是有效的,因为 Ref 用法隐式定义了对 MicroserviceLoadBalancerSGPrivate 的依赖。从技术上讲,redundantobsolete.

更正确

除非您特别需要在 MicroserviceLoadBalancerSGPrivate 之后创建 MicroserviceSG,否则您应该删除 DependsOn 并让 CloudFormation 执行此操作,因为 CloudFormation 将优化和并行化部署。


DependsOn 最常见的用途是按照特定顺序强制创建和删除资源,如文档所述:

You can use the DependsOn attribute with any resource. Here are some typical uses: Declare dependencies for resources that must be created or deleted in a specific order

DependsOn documentation 有更多关于您何时以及为什么要使用 DependsOn 的场景。