3

I have a requirement to create multiple databases in Postgres RDS provided by AWS using Cloudformation. I am able to create single database.

Below is snippet of my template :

"pgDB": {
    "Properties": {
        "AllocatedStorage": {
            "Ref": "Storage"
        },
        "DBInstanceClass": {
            "Ref": "DBInstanceClass"
        },
        "DBInstanceIdentifier": {
            "Ref": "DBInstanceName"
        },
        "DBName": {
            "Ref": "DBName"
        },
        "DBParameterGroupName": {
            "Ref": "myDBParamGroup"
        },
        "DBSubnetGroupName": {
            "Ref": "myDBSubnetGroup"
        },
        "Engine": "postgres",
        "MasterUserPassword": {
            "Ref": "DBPassword"
        },
        "MasterUsername": {
            "Ref": "DBUser"
        },
        "VPCSecurityGroups": [{
            "Fn::GetAtt": [
                "myDBEC2SecurityGroup",
                "GroupId"
            ]
        }]
    }
}
utkarsh-devops
  • 567
  • 7
  • 12

1 Answers1

4

Your CloudFormation resource pgDB should be of the type AWS::RDS::DBInstance, and therefore, it instructs CloudFormation to create one RDS instance. Each RDS instance can contain variable number of databases or database schemas.

CloudFormation does not provide means to provision the instance upon creation. To create Postgre databases on an RDS instance you have to use, for example, an EC2 instance to provision the database using stored SQL dumps or running plain commands, such as CREATE DATABASE, with psql. There is already a question regarding RDS provisioning.

You can create multiple RDS database instances by defining another AWS::RDS::DBInstance resource with its own parameters. By default, you can have 40 RDS Postgre instances on an account (see the limits in the FAQ).

Community
  • 1
  • 1
Olli
  • 649
  • 5
  • 15