Skip to content

Instantly share code, notes, and snippets.

@JensWalter
Created July 5, 2017 19:28
Show Gist options
  • Save JensWalter/6fabc564e530d46735192258dc786881 to your computer and use it in GitHub Desktop.
Save JensWalter/6fabc564e530d46735192258dc786881 to your computer and use it in GitHub Desktop.
Description: >
Aurora Database Cluster with one replication instance and Multi Availability Zones - CI & CD over AWS
Parameters:
DbPassword:
Type: String
Default: mypassword
Subnet1:
Type: String
Default: subnet-3671ca6c
Subnet2:
Type: String
Default: subnet-00b0cb48
Az1:
Type: String
Default: us-east-1b
Az2:
Type: String
Default: us-east-1a
Resources:
DBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Database Subnet Groups CI CD over AWS
SubnetIds:
- !Ref Subnet1
- !Ref Subnet2
RDSCluster:
Type: AWS::RDS::DBCluster
Properties:
MasterUsername: admin
MasterUserPassword: !Ref DbPassword
DatabaseName: myDB
Engine: aurora
DBSubnetGroupName: !Ref DBSubnetGroup
DBClusterParameterGroupName: !Ref RDSDBClusterParameterGroup
RDSDBInstance1:
Type: AWS::RDS::DBInstance
Properties:
DBSubnetGroupName:
Ref: DBSubnetGroup
DBParameterGroupName:
Ref: RDSDBParameterGroup
Engine: aurora
DBClusterIdentifier:
Ref: RDSCluster
PubliclyAccessible: 'false'
AvailabilityZone: !Ref Az1
DBInstanceClass: db.r3.large
RDSDBInstance2:
Type: AWS::RDS::DBInstance
Properties:
DBSubnetGroupName:
Ref: DBSubnetGroup
DBParameterGroupName:
Ref: RDSDBParameterGroup
Engine: aurora
DBClusterIdentifier:
Ref: RDSCluster
PubliclyAccessible: 'false'
AvailabilityZone: !Ref Az2
DBInstanceClass: db.r3.large
RDSDBClusterParameterGroup:
Type: AWS::RDS::DBClusterParameterGroup
Properties:
Description: CloudFormation Aurora Cluster Parameter Group CI CD over AWS
Family: aurora5.6
Parameters:
time_zone: US/Eastern
RDSDBParameterGroup:
Type: AWS::RDS::DBParameterGroup
Properties:
Description: CloudFormation Aurora Parameter Group CI CD over AWS
Family: aurora5.6
Parameters:
sql_mode: IGNORE_SPACE
Outputs:
dbClusterURL:
Description: Database Cluster URL Endpoint.
Value: !GetAtt RDSCluster.Endpoint.Address
Description: >
Main Architecture Template. Configuration based on CodeCommit, S3, ECS, Docker & RDS - CI & CD over AWS
Parameters:
DbPassword:
Type: String
Default: mypassword
Description: BackEnd DB Password
Resources:
VPC:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: cf-vpc.yml
Parameters:
Name: !Ref AWS::StackName
VpcCIDR: 10.10.0.0/16
Subnet1CIDR: 10.10.10.0/24
Subnet2CIDR: 10.10.20.0/24
DatabaseCluster:
Type: AWS::CloudFormation::Stack
Properties:
TemplateURL: cf-aurora.yml
Parameters:
DbPassword: !Ref DbPassword
Subnet1: !GetAtt VPC.Outputs.Subnet1
Subnet2: !GetAtt VPC.Outputs.Subnet2
Az1: !GetAtt VPC.Outputs.Az1
Az2: !GetAtt VPC.Outputs.Az2
Description: >
VPC cloudformation definition - CI & CD over AWS
Parameters:
Name:
Type: String
Default: test-vpc
VpcCIDR:
Type: String
Default: 10.10.0.0/16
Subnet1CIDR:
Type: String
Default: 10.10.10.0/24
Subnet2CIDR:
Type: String
Default: 10.10.20.0/24
Resources:
VPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: !Ref VpcCIDR
Tags:
- Key: Name
Value: !Ref Name
InternetGateway:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Ref Name
InternetGatewayAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref InternetGateway
VpcId: !Ref VPC
Subnet1:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 0, !GetAZs ]
MapPublicIpOnLaunch: true
CidrBlock: !Ref Subnet1CIDR
Tags:
- Key: Name
Value: !Sub ${Name} (Public)
Subnet2:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref VPC
AvailabilityZone: !Select [ 1, !GetAZs ]
MapPublicIpOnLaunch: true
CidrBlock: !Ref Subnet2CIDR
Tags:
- Key: Name
Value: !Sub ${Name} (Public)
RouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref VPC
Tags:
- Key: Name
Value: !Ref Name
DefaultRoute:
Type: AWS::EC2::Route
Properties:
RouteTableId: !Ref RouteTable
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref InternetGateway
Subnet1RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTable
SubnetId: !Ref Subnet1
Subnet2RouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
RouteTableId: !Ref RouteTable
SubnetId: !Ref Subnet2
Outputs:
Subnets:
Description: Subnets in a list format comma separated
Value: !Join [ ",", [ !Ref Subnet1, !Ref Subnet2 ] ]
Subnet1:
Description: Subnet 1 Created
Value: !Ref Subnet1
Subnet2:
Description: Subnet 2 Created
Value: !Ref Subnet2
Az1:
Description: Availability Zone 1 Created
Value: !GetAtt Subnet1.AvailabilityZone
Az2:
Description: Availability Zone 2 Created
Value: !GetAtt Subnet2.AvailabilityZone
VpcId:
Description: VPC logical ID
Value: !Ref VPC
VpcDefaultSG:
Description: VPC Deault Security Group
Value: !GetAtt VPC.DefaultSecurityGroup
aws cloudformation package --template-file cf-main.yml --s3-bucket sample5324bucket --output-template packaged-template.yml
aws cloudformation deploy --region us-east-1 --template-file packaged-template.yml --capabilities CAPABILITY_IAM --stack-name aurora5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment