Skip to content

Instantly share code, notes, and snippets.

@yuyasugano
Last active November 20, 2020 05:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yuyasugano/c58678688509b3954219d26ed5788b4b to your computer and use it in GitHub Desktop.
Save yuyasugano/c58678688509b3954219d26ed5788b4b to your computer and use it in GitHub Desktop.
AWS Aurora Global database deploy with Cloudformation
---
AWSTemplateFormatVersion: '2010-09-09'
Description: AWS Aurora Global database secondary region
Mappings:
MinorUpdateMap:
'Yes':
value: 'true'
'No':
value: 'false'
EngineMap:
# only 10.11, 10.12 or 11.7 later are supported for global databases
'11.7':
family: aurora-postgresql11
Parameters:
Environment:
Type: String
Default: dev
AllowedValues:
- dev
- prod
- uat
MachineType:
# global databases support either db.r4 or db.r5
Default: db.r4.large
Type: String
AllowedValues:
- db.r4.large
- db.r5.large
DatabaseName:
Default: globaldatabase
Type: String
MinorVersionUpgrade:
Default: 'No'
Type: String
AllowedValues:
- 'Yes'
- 'No'
PostgresVersion:
Default: '11.7'
Type: String
AllowedValues:
- '11.7'
PostgresEngineMode:
Default: 'provisioned'
Type: String
AllowedValues:
- 'global'
- 'provisioned'
ClusterName:
Default: dbcluster02
Type: String
GlobalClusterIdentifier:
Default: globaldbcluster
Type: String
Resources:
# GlobalDBCluster:
# DependsOn:
# - DBCluster
# Type: AWS::RDS::GlobalCluster
# Properties:
# GlobalClusterIdentifier: !Ref GlobalClusterIdentifier
# SourceDBClusterIdentifier: !Ref DBCluster
DBClusterParameterGroup:
Type: AWS::RDS::DBClusterParameterGroup
Properties:
Family: !FindInMap
- EngineMap
- !Ref PostgresVersion
- family
Parameters:
max_connections: 300
Description: DBClusterParameterGroup
DBParameterGroup:
Type: AWS::RDS::DBParameterGroup
Properties:
Family: !FindInMap
- EngineMap
- !Ref PostgresVersion
- family
Parameters:
max_connections: 300
Description: DBParameterGroup
DBCluster:
DependsOn:
- DBClusterParameterGroup
- SecurityGroup
- SubnetGroup
Type: AWS::RDS::DBCluster
Properties:
DBClusterIdentifier: !Ref ClusterName
DBClusterParameterGroupName: !Ref DBClusterParameterGroup
DBSubnetGroupName: !Ref SubnetGroup
# DatabaseName: !Ref DatabaseName
DeletionProtection: false
Engine: aurora-postgresql
EngineVersion: !Ref PostgresVersion
EngineMode: !Ref PostgresEngineMode
GlobalClusterIdentifier: !Ref GlobalClusterIdentifier
# MasterUsername: testuser
# MasterUserPassword: !Ref MasterPassword
Port: '5432'
StorageEncrypted: false
SourceRegion: ap-northeast-1
VpcSecurityGroupIds:
- !Ref SecurityGroup
DBInstance1:
DependsOn:
- DBParameterGroup
- DBCluster
- SubnetGroup
Type: AWS::RDS::DBInstance
Properties:
AllowMajorVersionUpgrade: false
AutoMinorVersionUpgrade: !FindInMap
- MinorUpdateMap
- !Ref MinorVersionUpgrade
- value
DBClusterIdentifier: !Ref DBCluster
DBInstanceIdentifier: !Sub '${ClusterName}-1'
DBInstanceClass: !Ref MachineType
DBParameterGroupName: !Ref DBParameterGroup
DBSubnetGroupName: !Ref SubnetGroup
Engine: aurora-postgresql
EngineVersion: !Ref PostgresVersion
PubliclyAccessible: false
SecurityGroup:
Type: AWS::EC2::SecurityGroup
Properties:
VpcId: vpc-<your vpc>
GroupDescription: Access to database
SecurityGroupIngress:
- ToPort: 5432
FromPort: 5432
IpProtocol: tcp
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Sub ${DatabaseName}-security-group
SubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
SubnetIds:
- subnet-<your subnet>
- subnet-<your subnet>
- subnet-<your subnet>
DBSubnetGroupDescription: !Sub ${DatabaseName}-subnet-group
Outputs:
DBEndpoint:
Value: !GetAtt DBCluster.Endpoint.Address
DBPort:
Value: !GetAtt DBCluster.Endpoint.Port
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment