2016-05-04 7 views
1

Wenn ich eine RDS-Instanz manuell starte, kann ich festlegen, zu welcher VPC ich gehören möchte. Ich versuche, mithilfe von AWS cloudformation einen Stack zu erstellen, sehe jedoch keine API, um dies zu tun. Ich kann meine VPC im Stapel erstellen und sie dann für Sicherheitsgruppen sowohl für EC2- als auch für DB-Sicherheitsgruppen referenzieren, und beide sind Teil der VPC, die RDS-Instanz jedoch nicht. Gibt es eine Möglichkeit, die VPC der RDS-Instanz zuzuweisen?So fügen Sie eine RDS-Instanz zu einer VPC mit aws cloudformation hinzu

Unten ist meine Vorlage:

{ 
    "AWSTemplateFormatVersion": "2010-09-09", 
    "Metadata": { 
    "AWS::CloudFormation::Designer": { 
     "30e03bfc-b61a-4d6c-89db-1b62b258a305": { 
     "size": { 
      "width": 80, 
      "height": 80 
     }, 
     "position": { 
      "x": 700, 
      "y": 170 
     }, 
     "z": 0, 
     "embeds": [] 
     } 
    } 
    }, 

    "Parameters": { 

    "DBPreferredBkupWindow": { 
     "Description"     : "The daily time range (in UTC) during which automated backups are created, ideally off peak-hours.", 
     "Type"      : "String", 
     "MinLength"     : "1", 
     "MaxLength"     : "11", 
     "AllowedPattern"    : "\\d[0-23]:\\d[0-59]-\\d[0-23]:\\d[0-59]", 
     "Default"      : "01:00-02:00" 
    } 
    }, 

    "Resources": { 

    "VPC": { 
     "Type": "AWS::EC2::VPC", 
     "Properties": { 
     "CidrBlock"     : "172.16.0.0/16", 
     "EnableDnsSupport"   : true 
     } 
    }, 

    "DB": { 
     "Type": "AWS::RDS::DBInstance", 
     "Properties": { 
     "DBName"     : "ems", 
     "Engine"     : "postgres", 
     "EngineVersion"    : "9.4.7", 
     "DBInstanceClass"   : "db.t1.micro", 
     "DBInstanceIdentifier"  : "rltdb", 
     "MasterUsername"   : "pgadmin", 
     "MasterUserPassword"  : "pgadmin1", 
     "AllocatedStorage"   : "100", 
     "Iops"      : "1000", 
     "BackupRetentionPeriod"  : "7", 
     "PreferredBackupWindow"  : { "Ref" : "DBPreferredBkupWindow" }, 
     "MultiAZ"     : true, 
     "PubliclyAccessible"  : false, 
     "AutoMinorVersionUpgrade" : false, 
     "VPCSecurityGroups"   : [{ "Ref" : "SecurityGroup" } ] 
     }, 

     "Metadata": { 
     "AWS::CloudFormation::Designer": { 
      "id": "30e03bfc-b61a-4d6c-89db-1b62b258a305" 
     } 
     } 
    }, 

    "DBSecurityGroup": { 
     "Type": "AWS::RDS::DBSecurityGroup", 
     "Properties": { 
     "EC2VpcId"     : { "Ref" : "VPC" }, 
     "DBSecurityGroupIngress" : { "EC2SecurityGroupName": { "Ref": "SecurityGroup"} }, 
     "GroupDescription"   : "Database Access" 
     } 
    }, 

    "SecurityGroup" : { 
     "Type" : "AWS::EC2::SecurityGroup", 
     "Properties" : { 
     "VpcId"      : { "Ref" : "VPC" }, 
     "GroupDescription"   : "Enable database access for application", 
     "SecurityGroupIngress"  : [ 
      {"IpProtocol" : "tcp", "FromPort" : "5432", "ToPort" : "5432", "CidrIp" : "0.0.0.0/0"} 
     ] 
     } 
    } 
    } 
} 

Antwort

2

Sie müssen schließen die DBSubnetGroupName:

Ein DB-Subnetz-Gruppe mit der DB-Instanz zuzuordnen.

Wenn keine DB-Subnetzgruppe vorhanden ist, handelt es sich um eine Nicht-VPC-DB-Instanz.

Erstellen eines DBSubnetGroup resource mit Subnetze in Ihrer VPC, dann ist das zu Ihrem DBINSTANCE binden:

"DBSubnetGroupName": { "Ref": "MySubnetGroup" } 
3

Sie haben ein DBSubnetGroup und mindestens zwei Subnetze in Ihrer Cloudformation-Vorlage zu erstellen.

"subnet-1" : { 
    "Type" : "AWS::EC2::Subnet", 
    "Properties" : { 
     "CidrBlock" : "172.16.1.0/24", 
     "VpcId" : { "Ref" : "VPC" } 
    } 
},  

"subnet-2" : { 
    "Type" : "AWS::EC2::Subnet", 
    "Properties" : { 
     "CidrBlock" : "172.16.2.0/24", 
     "VpcId" : { "Ref" : "VPC" } 
    } 
},  

"DBSubnetGroup" : { 
    "Type" : "AWS::RDS::DBSubnetGroup", 
    "Properties" : { 
     "SubnetIds" : [ 
      { "Ref" : "subnet-1" }, 
      { "Ref" : "subnet-2" } 
     ], 
    } 
}, 

und zuletzt müssen Sie DBSubnetGroup in Ihrem "DB" Objekt umfassen.

"DBSubnetGroupName": { "Ref": "DBSubnetGroup" }