-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrds.yml
107 lines (107 loc) · 3.32 KB
/
rds.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
Resources:
TodoSubnetGroup:
Type: "AWS::RDS::DBSubnetGroup"
Properties:
DBSubnetGroupDescription: Group of private subnets for Aurora cluster.
SubnetIds:
- Ref: ServerlessSubnetA
- Ref: ServerlessSubnetB
TodoDBSecurityGroup:
Metadata:
"aws:copilot:description": "A security group for your workload to access the DB cluster"
Type: "AWS::EC2::SecurityGroup"
Properties:
GroupDescription: The Security Group for the database cluster.
VpcId:
Ref: ServerlessVPC
SecurityGroupIngress:
- ToPort: 3306
FromPort: 3306
IpProtocol: tcp
SourceSecurityGroupId:
Ref: ServerlessSecurityGroup
TodoDBRDSCluster:
Type: AWS::RDS::DBCluster
Properties:
MasterUsername:
Fn::Join: [
"",
[
"{{resolve:secretsmanager:",
Ref: TodoClusterAuroraSecret,
":SecretString:username}}",
],
]
MasterUserPassword:
Fn::Join: [
"",
[
"{{resolve:secretsmanager:",
Ref: TodoClusterAuroraSecret,
":SecretString:password}}",
],
]
DBSubnetGroupName:
Ref: TodoSubnetGroup
Engine: "aurora-mysql"
EngineVersion: "5.7.mysql_aurora.2.07.1"
EngineMode: serverless
DatabaseName: todo_${env:STAGE}
DBClusterParameterGroupName:
Ref: TodoDBRDSClusterParameter
ScalingConfiguration:
AutoPause: true
MinCapacity: 1
MaxCapacity: 4
SecondsUntilAutoPause: "1000"
TodoDBRDSClusterParameter:
Type: AWS::RDS::DBClusterParameterGroup
Properties:
Description: Parameter group for the Serverless Aurora RDS DB.
Family: "aurora-mysql5.7"
Parameters:
character_set_database: "utf8"
TodoDBRDSParameterGroup:
Type: AWS::RDS::DBParameterGroup
Properties:
Description: Parameter group for the Serverless Aurora RDS DB.
Family: "aurora-mysql5.7"
Parameters:
sql_mode: IGNORE_SPACE
max_connections: 100
wait_timeout: 900
interactive_timeout: 900
TodoClusterAuroraSecret:
Metadata:
"aws:copilot:description": "A Secrets Manager secret to store your DB credentials"
Type: AWS::SecretsManager::Secret
Properties:
Description:
Fn::Sub: Aurora main user secret for dev
GenerateSecretString:
SecretStringTemplate: '{"username": "admin"}'
GenerateStringKey: "password"
ExcludePunctuation: true
IncludeSpace: false
PasswordLength: 16
TodoClusterSecretAuroraClusterAttachment:
Type: AWS::SecretsManager::SecretTargetAttachment
Properties:
SecretId:
Ref: TodoClusterAuroraSecret
TargetId:
Ref: TodoDBRDSCluster
TargetType: AWS::RDS::DBCluster
Outputs:
TodoRDSHost:
Description: Host of the Todo RDS instance
Value:
Fn::GetAtt: [TodoDBRDSCluster, Endpoint.Address]
TodoRDSPort:
Description: Port of the Todo RDS instance
Value:
Fn::GetAtt: [TodoDBRDSCluster, Endpoint.Port]
TodoClusterSecret:
Description: "The JSON secret that holds the database username and password. Fields are 'host', 'port', 'dbname', 'username', 'password', 'dbClusterIdentifier' and 'engine'"
Value:
Ref: TodoClusterAuroraSecret