Hayden Eastwood
Hayden Eastwood

Reputation: 966

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

I am attempting to geneate an Aurora serverless database for an application using Serverless to build it.

I copied a CloudFormation template I found online for this portion of my setup. I reference the below resource from my Serverless.yml file (which I've excluded because it's very large).

Serverless fails with the message:

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

I am confused about this because, to my observation, DBSubnetGroupName is a string (which as you can see is set to the value of 'db-subnet-group').

I am new to both Serverless and CloudFormation, and am doing my best to piece a solution together for a product I am building. Any suggestion as to how to fix this problem would be much appreciated.

Below is my Serverless file. Many thanks in advance for any assistance!

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

Upvotes: 1

Views: 724

Answers (2)

pgrzesik
pgrzesik

Reputation: 2427

In your example, you're passing DBSubnetGroupName as an array, not a string:

DBSubnetGroupName:
  - Ref: AuroraSubnetGroup

In order to pass it as a string, you should use this notation:

DBSubnetGroupName: Ref: AuroraSubnetGroup

Upvotes: 1

Marcin
Marcin

Reputation: 238299

In your AWS::RDS::DBCluster it should be:

      DBSubnetGroupName: !Ref AuroraSubnetGroup

Upvotes: 1

Related Questions