-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
Copy pathtemplate-vpcrds.yml
125 lines (125 loc) · 3.61 KB
/
template-vpcrds.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
AWSTemplateFormatVersion: 2010-09-09
Parameters:
databaseName:
Default: lambdadb
Description: Database name
Type: String
MinLength: '1'
MaxLength: '64'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: Begin with a letter and use only alphanumeric characters.
databaseUser:
NoEcho: 'true'
Description: Database username
Default: admin
Type: String
MinLength: '1'
MaxLength: '16'
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: Begin with a letter and use only alphanumeric characters.
Resources:
databaseSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Subnets
SubnetIds:
- !Ref privateSubnetA
- !Ref privateSubnetB
database:
Type: AWS::RDS::DBInstance
Properties:
DBName: !Ref databaseName
AllocatedStorage: '10'
DBInstanceClass: db.t3.small
Engine: MySQL
EngineVersion: 5.7.38
MasterUsername: !Ref 'databaseUser'
MasterUserPassword: '{{resolve:secretsmanager:rds-mysql-admin:SecretString:password}}'
DeletionProtection: true
MultiAZ: true
DBSubnetGroupName: !Ref databaseSubnetGroup
VPCSecurityGroups:
- !GetAtt privateVPC.DefaultSecurityGroup
privateVPC:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 172.31.0.0/16
Tags:
- Key: Name
Value: !Ref AWS::StackName
privateSubnetA:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref privateVPC
AvailabilityZone:
Fn::Select:
- 0
- Fn::GetAZs: ""
CidrBlock: 172.31.3.0/24
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Join ["-", [!Ref "AWS::StackName","subnet-a"]]
privateSubnetB:
Type: AWS::EC2::Subnet
Properties:
VpcId: !Ref privateVPC
AvailabilityZone:
Fn::Select:
- 1
- Fn::GetAZs: ""
CidrBlock: 172.31.2.0/24
MapPublicIpOnLaunch: false
Tags:
- Key: Name
Value: !Join ["-", [!Ref "AWS::StackName","subnet-b"]]
privateRouteTable:
Type: AWS::EC2::RouteTable
Properties:
VpcId: !Ref privateVPC
privateSubnetARouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref privateSubnetA
RouteTableId: !Ref privateRouteTable
privateSubnetBRouteTableAssociation:
Type: AWS::EC2::SubnetRouteTableAssociation
Properties:
SubnetId: !Ref privateSubnetB
RouteTableId: !Ref privateRouteTable
Outputs:
privateVPCSecurityGroup:
Description: Default security for Lambda VPC
Value: !GetAtt privateVPC.DefaultSecurityGroup
Export:
Name: !Join ["-", [!Ref "AWS::StackName","vpc-sg"]]
privateVPCID:
Description: VPC ID
Value: !Ref privateVPC
Export:
Name: !Join ["-", [!Ref "AWS::StackName","vpc"]]
privateSubnetAID:
Description: Private Subnet A ID
Value: !Ref privateSubnetA
Export:
Name: !Join ["-", [!Ref "AWS::StackName","subnet-a"]]
privateSubnetBID:
Description: Private Subnet B ID
Value: !Ref privateSubnetB
Export:
Name: !Join ["-", [!Ref "AWS::StackName","subnet-b"]]
databaseHost:
Description: Database hostname
Value: !GetAtt database.Endpoint.Address
Export:
Name: !Join ["-", [!Ref "AWS::StackName","db-host"]]
databaseName:
Description: Database name
Value: !Ref databaseName
Export:
Name: !Join ["-", [!Ref "AWS::StackName","db-name"]]
databaseUser:
Description: Database user
Value: !Ref databaseUser
Export:
Name: !Join ["-", [!Ref "AWS::StackName","db-user"]]