首页 > 解决方案 > CFT 模板错误:Fn::If 中未解决的条件依赖 UseDBSnapshot

问题描述

尝试为 RDS 创建一个 CFT,它可以处理创建新 RDS Aurora MySQL 集群和使用现有数据库集群快照创建 RDS 集群的两种场景

这是我尝试过的,

我提供了模板的以下条件部分

"UseDbSnapshot" : {
              "Fn::Not" : [
                  {
                      "Fn::Equals":[
                            {"Ref": "DBSnapshotName"},
                            ""
                        ]
                    }
                ]
            }

并在以下资源部分中引用

"RDSCluster1": {
        "Type": "AWS::RDS::DBCluster",
        "Condition": "isResourceCreate",
        "Properties": {
            "Engine": "aurora",
            "DBSubnetGroupName": {
                "Ref": "DBSubnetGroup"
            },
            "DBClusterParameterGroupName": {
                "Ref": "RDSDBClusterParameterGroup"
            },
            "DBSnapshotIdentifier" : {
                "Fn::If" : [
                  "UseDBSnapshot",
                  {"Ref" : "DBSnapshotName"},
                  {"Ref" : "AWS::NoValue"}
                ]
              },
            "MasterUsername": {
                "Ref": "DbUser"
            },
            "MasterUserPassword": {
                "Ref": "MasterUserPassword"
            },
            "StorageEncrypted" : true,
            "KmsKeyId" : {
                "Ref": "KmsKeyId"
            },
            "VpcSecurityGroupIds": [
                {
                    "Fn::GetAtt": [
                        "DBAccessSecurityGroup",
                        "GroupId"
                    ]
                }
            ],
            "Port": "3306",
            "BackupRetentionPeriod": "1"
        },
        "DeletionPolicy": "Snapshot"
    }

条件“isResourceCreate”得到满足,但我得到以下错误

模板错误:Fn::If 中未解决的条件依赖 UseDBSnapshot

你能帮我吗?

已查找在线链接https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/conditions-sample-templates.html 并创建了此 CFT。

如果您需要更多详细信息,请告诉我。

标签: jsonamazon-web-servicesamazon-cloudformationamazon-rds

解决方案


如果要从快照恢复数据库,则不能提供 MasterUsernameMasterUserPassword. 这些值将从快照继承,因此您必须将它们设为可选

如果您指定 SourceDBInstanceIdentifier 或 DBSnapshotIdentifier 属性,请不要指定此属性。该值继承自源数据库实例或快照


推荐阅读