Skip to content
Permalink
Branch: master
Find file Copy path
Find file Copy path
1 contributor

Users who have contributed to this file

188 lines (187 sloc) 5.11 KB
Description:
This template deploys a VPC with a pair of subnets spread
across two Availability Zones. It deploys an Internet Gateway,
with a default route on the public subnets. It deploys an RDS
PostgreSQL master and single read replica databaes.
Parameters:
VpcCIDR:
Description: IP range (CIDR notation) for this VPC
Type: String
Default: "10.0.0.0/24"
AllowedPattern: "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}"
SubnetMasterCIDR:
Description: IP range (CIDR notation) for the subnet in the RDS Master Availability Zone
Type: String
Default: "10.0.0.0/28"
AllowedPattern: "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}"
SubnetReplicaCIDR:
Description: IP range (CIDR notation) for the subnet in the RDS Read Replica Availability Zone
Type: String
Default: "10.0.0.16/28"
AllowedPattern: "((\\d{1,3})\\.){3}\\d{1,3}/\\d{1,2}"
DBInstanceIdentifier:
Type: String
Default: "demo-instance"
ReplicaInstanceIdentifier:
Type: String
Default: "demo-replica"
DBEngine:
Type: String
Default: "postgres"
DBEngineVersion:
Type: String
Default: "11.4"
DBSourceRegion:
Type: String
Default: "us-east-1"
DBInstanceClass:
Type: String
Default: "db.t3.small"
DBStorageType:
Type: String
Default: "gp2"
DBAllocatedStorage:
Type: Number
Default: 10
DBName:
Type: String
Default: "{{resolve:ssm:/rds_demo/db_name:1}}"
DBUser:
Type: String
Default: "{{resolve:ssm:/rds_demo/master_username:1}}"
DBPassword:
Type: String
Default: "{{resolve:ssm-secure:/rds_demo/master_password:1}}"
NoEcho: True
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCIDR
EnableDnsSupport: true
EnableDnsHostnames: true
Tags:
- Key: Name
Value: Demo VPC
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: Internet Gateway
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
SubnetMasterDB:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs '' ]
CidrBlock: !Ref SubnetMasterCIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: Master Subnet (AZ1)
SubnetReplicaDB:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 1, !GetAZs '' ]
CidrBlock: !Ref SubnetReplicaCIDR
MapPublicIpOnLaunch: true
Tags:
- Key: Name
Value: Replica Subnet (AZ2)
PublicRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: Public Route Table
DefaultPublicRoute:
Type: AWS::EC2::Route
DependsOn: InternetGatewayAttachment
Properties:
RouteTableId: !Ref PublicRouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
SubnetMasterRouteTableAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref SubnetMasterDB
SubnetReplicaRouteTableAssoc:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref PublicRouteTable
SubnetId: !Ref SubnetReplicaDB
DBSubnetGroup:
Properties:
DBSubnetGroupDescription: DBSubnetGroup for RDS instances
SubnetIds:
- Ref: SubnetMasterDB
- Ref: SubnetReplicaDB
Type: AWS::RDS::DBSubnetGroup
VpcDefaultSecurityGroupIngress:
Type: AWS::EC2::SecurityGroupIngress
Properties:
GroupId: !GetAtt VPC.DefaultSecurityGroup
CidrIp: 0.0.0.0/0
IpProtocol: tcp
FromPort: 5432
ToPort: 5432
DemoMasterInstance:
Properties:
DBInstanceIdentifier:
Ref: DBInstanceIdentifier
DBName:
Ref: DBName
AllocatedStorage:
Ref: DBAllocatedStorage
DBInstanceClass:
Ref: DBInstanceClass
StorageType:
Ref: DBStorageType
Engine:
Ref: DBEngine
EngineVersion:
Ref: DBEngineVersion
MasterUsername:
Ref: DBUser
MasterUserPassword:
Ref: DBPassword
PubliclyAccessible: True
Tags:
- Key: Name
Value: "Demo RDS PostgreSQL Master"
VPCSecurityGroups:
- !GetAtt VPC.DefaultSecurityGroup
DBSubnetGroupName:
Ref: DBSubnetGroup
Type: AWS::RDS::DBInstance
DemoReadReplica:
Properties:
DBInstanceIdentifier:
Ref: ReplicaInstanceIdentifier
AllocatedStorage:
Ref: DBAllocatedStorage
DBInstanceClass:
Ref: DBInstanceClass
SourceDBInstanceIdentifier:
Ref: DemoMasterInstance
SourceRegion:
Ref: DBSourceRegion
Tags:
- Key: Name
Value: "Demo RDS PostgreSQL Read Replica"
Type: AWS::RDS::DBInstance
Outputs:
EndpointMaster:
Description: "Endpoint of the newly created RDS master"
Value: DemoMasterInstance
EndpointReplica:
Description: "Endpoint of the newly created RDS replica"
Value: DemoReadReplica
You can’t perform that action at this time.