无服务器错误 - 属性 DBSubnetGroupName 的值必须是字符串类型

Serverless error - Value of property DBSubnetGroupName must be of type String

我正在尝试为使用 Serverless 构建的应用程序生成 Aurora 无服务器数据库。

我为我的这部分设置复制了一个在网上找到的 CloudFormation 模板。我从我的 Serverless.yml 文件中引用了以下资源(我已将其排除,因为它非常大)。

Serverless 失败并显示消息:

An error occurred: AuroraCluster - Value of property DBSubnetGroupName must be of type String.

我对此感到困惑,因为根据我的观察,DBSubnetGroupName 是一个字符串(如您所见,它被设置为 'db-subnet-group' 的值)。

我是无服务器和 CloudFormation 的新手,我正在尽我最大的努力为我正在构建的产品拼凑出一个解决方案。任何有关如何解决此问题的建议将不胜感激。

下面是我的无服务器文件。非常感谢您的帮助!

Resources:
  ServerlessSecurityGroup:
    DependsOn: VPC
    Type: AWS::EC2::SecurityGroup
    Properties:
        GroupDescription: SecurityGroup for Serverless Functions
        VpcId:
            Ref: VPC

  PrivateSubnetA:
    DependsOn: VPC
    Type: AWS::EC2::Subnet
    Properties:
        VpcId:
            Ref: VPC
        AvailabilityZone: "eu-west-1a"
        CidrBlock: "10.0.1.0/24"

  PrivateSubnetB:
    DependsOn: VPC
    Type: AWS::EC2::Subnet
    Properties:
      VpcId:
        Ref: VPC
      AvailabilityZone: "eu-west-1b"
      CidrBlock: "10.0.64.0/19"

  AuroraSubnetGroup:
    Type: AWS::RDS::DBSubnetGroup
    Properties:
        DBSubnetGroupDescription: Subnet group for Aurora Database
        DBSubnetGroupName: "db-subnet-group"
        SubnetIds:
          - Ref: PrivateSubnetA
          - Ref: PrivateSubnetB

  AuroraCluster:
    Type: AWS::RDS::DBCluster
    DeletionPolicy: ${self:custom.deletion_policy}
    Properties:
      DBClusterIdentifier: ${self:custom.aurora_db_name}
      MasterUsername: !Sub ${self:custom.aurora_db_name}
      MasterUserPassword: asdfasdfasdf223
      DatabaseName: "somename"
      Engine: aurora
      EngineMode: serverless
      DBSubnetGroupName:
        - Ref: AuroraSubnetGroup
      VpcSecurityGroupIds:
        - Ref: ServerlessSecurityGroup
      EnableHttpEndpoint: true
      ScalingConfiguration:
        AutoPause: true
        MinCapacity: 1
        MaxCapacity: 2
        SecondsUntilAutoPause: 3600

Outputs:
  AuroraCluster:
    Value:
      Ref: AuroraCluster

在你的 AWS::RDS::DBCluster 中应该是:

      DBSubnetGroupName: !Ref AuroraSubnetGroup

在您的示例中,您将 DBSubnetGroupName 作为数组而不是字符串传递:

DBSubnetGroupName:
  - Ref: AuroraSubnetGroup

为了将其作为字符串传递,您应该使用这种表示法:

DBSubnetGroupName: Ref: AuroraSubnetGroup