【问题标题】:CloudFormation fails to find RDS Subnet Group because of lowercaseCloudFormation 因小写而无法找到 RDS 子网组
【发布时间】:2022-03-18 16:44:19
【问题描述】:

我通过引用参数 ProjectName 的 CloudFormation 创建了我的 RDS 子网组

  DB:
    Type: AWS::RDS::DBInstance
    Properties:
      DBSubnetGroupName: !Ref RDSSubnetGroup

现在的问题是 CloudFormation 说它找不到我的子网组:

DB 子网组 'AbcDef' 不存在,因为它实际上是 abcdef ...我该如何解决这个问题?

我尝试寻找 toLower 函数,但似乎没有?

另一个选项似乎是重新创建堆栈?

【问题讨论】:

    标签: amazon-web-services amazon-cloudformation


    【解决方案1】:

    不幸的是,您在CloudFormation 模板中所做的一切都是区分大小写的,包括属性名称和参数值。您可能需要重新创建堆栈。

    正如您正确指出的那样,没有Fn::ToLower 功能。如果你真的想实现你想要的,那么目前唯一的方法是创建Lambda backed custom resource,它基本上会将你的字符串转换为小写并返回它,但它不值得这样做,因为有很多处理自定义资源时会遇到的挑战。

    【讨论】:

      【解决方案2】:

      我还发现在 RDS 控制台中查看时,DB 子网组的名称被强制更改为小写。非常不寻常的行为。

      但是,我在 CloudFormation 中创建了它们,它并没有导致您描述的错误。以下是我的 CloudFormation 模板中的部分内容:

      ###########
      # DB Subnet Group
      ###########
      
        DBSubnetGroup:
          Type: AWS::RDS::DBSubnetGroup
          Properties: 
            DBSubnetGroupDescription: Lab DB Subnet Group
            DBSubnetGroupName: Lab DB Subnet Group
            SubnetIds:
              - !Ref PrivateSubnet1
              - !Ref PrivateSubnet2
            Tags:
              -
                Key: Name
                Value: DBSubnetGroup
      
      ###########
      # RDS Database
      ###########
      
        RDSDatabase:
          Type: AWS::RDS::DBInstance
          Properties:
            DBName: inventory
            DBInstanceIdentifier: inventory-db
            AllocatedStorage: 5
            DBInstanceClass: db.t2.micro
            Engine: MySQL
            MasterUsername: master
            MasterUserPassword: lab-password
            MultiAZ: false
            DBSubnetGroupName: !Ref DBSubnetGroup
            VPCSecurityGroups:
              - !Ref DBSecurityGroup
            Tags:
              -
                Key: Name
                Value: inventory-db
      

      【讨论】:

        【解决方案3】:

        我建议将DBSubnetGroup的function_name和名称重写为dbsubnetgroup

        这将解决我认为的问题。

        【讨论】:

          【解决方案4】:

          遇到了同样的问题,尝试了所有可能的方法,唯一的解决方法是创建一个名称为 lower 的新数据库子网组:

            rdssubnetgrouplower:
              Type: "AWS::RDS::DBSubnetGroup"
              Properties:
                DBSubnetGroupDescription: "Private subnet group to keep the cluster private"
                DBSubnetGroupName: rdssubnetgrouplower
                SubnetIds:
                  - !Ref PrivateSubnet1
                  - !Ref PrivateSubnet2
                Tags:
                  -
                    Key: Name
                    Value: rdssubnetgrouplower
          

          然后在 RDS 定义中使用它:

            MySQLABC:
              Type: "AWS::RDS::DBCluster"
              Properties:
                DBSubnetGroupName: !Ref rdssubnetgrouplower
                ...
                ...
          

          这很有效,并且集群已经启动。在 TF 中有较低的功能:)

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2021-01-08
            • 2021-03-20
            • 1970-01-01
            • 2021-01-13
            • 2021-01-18
            • 2020-12-08
            • 2023-03-24
            相关资源
            最近更新 更多