forked from aws-samples/aws-secretsmgr-workshop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1_RotatePublicRDS.yaml
742 lines (654 loc) · 23.2 KB
/
1_RotatePublicRDS.yaml
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
# Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy of this
# software and associated documentation files (the "Software"), to deal in the Software
# without restriction, including without limitation the rights to use, copy, modify,
# merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
# HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
---
AWSTemplateFormatVersion: '2010-09-09'
Description: Demo environment for AWS Secrets Manager with public RDS rotation.
# SecretsManagerDemoPublicRDS.yaml
#
# This CloudFormation template creates infrastructure for demonstrating
# AWS Secrets Manager using a public RDS database.
#
# The template builds the following:
#
# - An Internet gateway
# - Two public subnets (PubSubnet01 and 02)
# - A public route Table (PubRouteTable) with a default route pointing to
# the Internet gateway
# - An EC2 instance running the Amazon Linux 2 operating system (Bastion)
# which is installed on PubSubnet01
# - A security group for the EC2 instance (BastionSG)
# - Two bash scripts on the bastion instance
# mysql.oldway.sh - connect to the database with hard-coded passwords
# mysql.newway.sh - connect to the database with secrets manager
# - A public RDS database
#
# SECURITY NOTE:
#
# The purpose of this template is to give a simple demonstration of AWS
# Secrets Manager. To simplify the demo, the EC2 bastion host and the RDS
# database are on public subnets and OPEN TO THE INTERNET. You should
# delete this CloudFormation stack after you have completed the demo.
# Please consult the Secrets Manager user guide for information on how to
# use Secrets Manager in a more secure manner.
Metadata:
AWS::CloudFormation::Interface:
ParameterGroups:
-
Label:
default: 'SECURITY NOTE: Please delete this stack after you complete this demo!'
Parameters:
- AZName01
- AZName02
- BastionKeyPair
- DBName
- DBPort
- NamePrefix
- ProjectTag
-
Label:
default: 'SECURITY NOTE: Please delete this stack after you complete this demo!'
ParameterLabels:
AZName01:
default: 'Choose an Avaiability Zone:'
AZName02:
default: 'Choose a second Avaiability Zone:'
BastionKeyPair:
default: 'Choose a key pair:'
DBName:
default: 'Enter the name of the database:'
DBPort:
default: 'Enter the TCP port for the database endpoint:'
NamePrefix:
default: 'Enter a prefix for the Name tag:'
ProjectTag:
default: 'Enter the value for the Project tag:'
Parameters:
# NamePrefix - A prefix to apply to the Name tag of taggable resources.
# The Name tag will be set to the NamePrefix, a dash ("-"), and a suffix
# that varies based on the resource. You would typically accept the default.
NamePrefix:
Type: String
Default: 'smdemo'
MinLength: 2
MaxLength: 15
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
# ProjectTag - A value to apply to the Project tag of taggable resources. You
# would typically accept the default.
ProjectTag:
Type: String
Default: 'smproj'
MinLength: 2
MaxLength: 15
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
# AZName01 and AZName02 - The two Availability Zones to use for building subnets.
# Two are needed because a DB subnet group requires two different AZs.
AZName01:
Type: AWS::EC2::AvailabilityZone::Name
AZName02:
Type: AWS::EC2::AvailabilityZone::Name
# BastionKeyPair - The EC2 keypair for the bastion host.
BastionKeyPair:
Type: AWS::EC2::KeyPair::KeyName
# DBName - The RDS database instance name for the MySQL database.
# You would typically accept the default.
DBName:
Default: 'smdemo'
Type: String
MinLength: 1
MaxLength: 64
AllowedPattern: '[a-zA-Z][a-zA-Z0-9]*'
ConstraintDescription: 'Up to 64 alphanumerics beginning with a letter'
# DBPort - The TCP port for the MySQL RDS database. You should typically
# accept the default.
DBPort:
Default: 3306
Type: Number
MinValue: 1024
MaxValue: 65535
ConstraintDescription: 'Must be between 1024 and 65535'
Resources:
# VpcName - Our VPC
VpcName:
Type: AWS::EC2::VPC
Properties:
CidrBlock: 10.200.0.0/16
EnableDnsSupport: 'true'
EnableDnsHostnames: 'true'
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-vpc' ]]
- Key: Project
Value: !Ref ProjectTag
# PubSubnet01 and PubSubnet02 - Public subnets. Note that the EC2 and
# RDS instances only go into PubSubnet01. We need, however, another
# subnet for the DB subnet group regardless.
PubSubnet01:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Ref AZName01
CidrBlock: 10.200.11.0/24
MapPublicIpOnLaunch: 'true'
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-pubsn01' ]]
- Key: Project
Value: !Ref ProjectTag
VpcId: !Ref VpcName
PubSubnet02:
Type: AWS::EC2::Subnet
Properties:
AvailabilityZone: !Ref AZName02
CidrBlock: 10.200.12.0/24
MapPublicIpOnLaunch: 'true'
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-pubsn02' ]]
- Key: Project
Value: !Ref ProjectTag
VpcId: !Ref VpcName
# VpcIgw and VpcIgwAttachment - Set up the Internet gateway
# and the attachment.
VpcIgw:
Type: AWS::EC2::InternetGateway
Properties:
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-igw' ]]
- Key: Project
Value: !Ref ProjectTag
VpcIgwAttachment:
Type: AWS::EC2::VPCGatewayAttachment
Properties:
InternetGatewayId: !Ref VpcIgw
VpcId: !Ref VpcName
# PubRouteTable - The public routing table.
PubRouteTable:
Type: AWS::EC2::RouteTable
DependsOn: VpcIgwAttachment
Properties:
VpcId: !Ref VpcName
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-pubrtb' ]]
- Key: Project
Value: !Ref ProjectTag
# DefaultPubRoute - The default route to the public internet.
DefaultPubRoute:
Type: AWS::EC2::Route
DependsOn: VpcIgwAttachment
Properties:
DestinationCidrBlock: 0.0.0.0/0
GatewayId: !Ref VpcIgw
RouteTableId: !Ref PubRouteTable
# PubSubnet01PubRtb and PubSubnet02PubRtb - Associate subnets
# with the routng table.
PubSubnet01PubRtb:
Type: AWS::EC2::SubnetRouteTableAssociation
DependsOn: VpcIgwAttachment
Properties:
RouteTableId: !Ref PubRouteTable
SubnetId: !Ref PubSubnet01
PubSubnet02PubRtb:
Type: AWS::EC2::SubnetRouteTableAssociation
DependsOn: VpcIgwAttachment
Properties:
RouteTableId: !Ref PubRouteTable
SubnetId: !Ref PubSubnet02
# BastionSG - The security group for ssh on the bastion host., This
# is open to the Internet.
BastionSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: '22'
ToPort: '22'
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-sg01' ]]
- Key: Project
Value: !Ref ProjectTag
VpcId: !Ref VpcName
# BastionRole - The instance role for the bastion host. We only need
# permissions for Secrets Manager and KMS for this demo.
BastionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- ec2.amazonaws.com
Action:
- sts:AssumeRole
Path: '/'
Policies:
- PolicyName: !Join [ '', [ Ref: NamePrefix, '-CloudWatch' ]]
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- cloudwatch:PutMetricData
Resource: '*'
- PolicyName: !Join [ '', [ Ref: NamePrefix, '-CloudWatchLogs' ]]
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
- logs:DescribeLogStreams
Resource: arn:aws:logs:*:*:*
- PolicyName: !Join [ '', [ Ref: NamePrefix, '-SecretsManager' ]]
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- secretsmanager:*
Resource: '*'
- PolicyName: !Join [ '', [ Ref: NamePrefix, '-KMS' ]]
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- kms:*
Resource: '*'
# BastionProfile - The instance profile for the bastion host which just
# contains the corresponding IAM role.
BastionProfile:
Type: AWS::IAM::InstanceProfile
Properties:
Path: '/'
Roles:
- !Ref BastionRole
# Bastion - Our bastion host. Note that we launch this with the BastionProfile
# instance profile so we get access to some AWS services. We also create the
# take advantage of CloudFormation::Init to do some initialization create files,
# install packages, and run commands.
#
# FIles created:
#
# mysql.oldway.sh - shows the old way of connecting to the datbases with
# hardcoded credentials
#
# mysql.newway.sh - shows the new way of connecting to the database with
# AWS Secrets Manager
#
# Packages installed:
#
# jq - for parsing the strings from Secrets Manager
# python3 - for building the newest AWS CLI which has the most updated commands
#
# Additionally:
#
# (1) Install the LAMP (Linux-Apache-MariaDB-PHP) stack using
# amazon-linux-extras. We just need the mysql client and this is an easy
# way of getting it.
#
# (2) Build the latest AWS CLI which has the latest commands
#
# (3) Apply updates - twice for good measure!
Bastion:
Type: AWS::EC2::Instance
DependsOn:
- VpcIgwAttachment
- DBInstance
Metadata:
AWS::CloudFormation::Init:
configSets:
default:
- BastionSetup
BastionSetup:
packages:
yum:
jq: []
python3: []
files:
/home/ec2-user/mysql.oldway.sh:
content: !Sub |
#/bin/bash
# mysql.oldway.sh
# This is the old way of accessing a database, with hard-coded passwords.
# This script will only work right after the CloudFormation script runs.
# After you store and rotate the secret, you will need to use the
# mysql.newway.sh script.
mysql \
-p${DBMasterPassword.RandomString} \
-u ${DBMasterUser.RandomString} \
-P ${DBPort} \
-h ${DBInstance.Endpoint.Address}
mode: '755'
owner: ec2-user
group: ec2-user
/home/ec2-user/mysql.newway.sh:
content: !Sub |
#/bin/bash
# This is the new way of accessing a database, with AWS Secrets Manager.
if [ $# -ne 1 ]
then
echo usage: $0 SecretName
exit 1
fi
secret=$(aws secretsmanager get-secret-value --secret-id $1 --region ${AWS::Region} | jq .SecretString | jq fromjson)
user=$(echo $secret | jq -r .username)
password=$(echo $secret | jq -r .password)
endpoint=$(echo $secret | jq -r .host)
port=$(echo $secret | jq -r .port)
mysql \
-p$password \
-u $user \
-P $port \
-h $endpoint
mode: '755'
owner: ec2-user
group: ec2-user
/tmp/awscli-bundle.zip:
source: https://s3.amazonaws.com/aws-cli/awscli-bundle.zip
mode: '755'
commands:
cmd10mariadb:
command: 'amazon-linux-extras install lamp-mariadb10.2-php7.2'
cmd20unzipcli:
command: 'unzip awscli-bundle.zip'
cwd: '/tmp'
cmd30installcli:
command: './awscli-bundle/install -i /usr/local/aws -b /usr/local/bin/aws'
cwd: '/tmp'
CreationPolicy:
ResourceSignal:
Timeout: PT15M
Properties:
AvailabilityZone: !Ref AZName01
IamInstanceProfile: !Ref BastionProfile
ImageId: !GetAtt AMIInfo.Id
InstanceInitiatedShutdownBehavior: stop
InstanceType: t2.micro
KeyName: !Ref BastionKeyPair
Monitoring: true
NetworkInterfaces:
- AssociatePublicIpAddress: true
DeviceIndex: '0'
GroupSet:
- !Ref BastionSG
SubnetId: !Ref PubSubnet01
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-host' ]]
- Key: Project
Value: !Ref ProjectTag
Tenancy: default
UserData:
Fn::Base64: !Sub |
#!/bin/bash -xe
/opt/aws/bin/cfn-init -v --stack ${AWS::StackName} --resource Bastion --region ${AWS::Region}
mysql -p${DBMasterPassword.RandomString} -u ${DBMasterUser.RandomString} -P ${DBPort} -h ${DBInstance.Endpoint.Address} <<EOF
USE ${DBName}
CREATE TABLE bookinfo (BookId int, BookTitle varchar(255), BookAuthor varchar(255));
INSERT INTO bookinfo (BookId, BookTitle, BookAuthor) VALUES (1, "A Tale of Two Cities", "Charles Dickens");
EOF
/opt/aws/bin/cfn-signal -e $? --stack ${AWS::StackName} --resource Bastion --region ${AWS::Region}
# Create a Lambda excution role for the AMI lookup Lambda function
LambdaExecutionRole:
Type: AWS::IAM::Role
Properties:
AssumeRolePolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- sts:AssumeRole
Path: '/'
Policies:
- PolicyName: root
PolicyDocument:
Version: '2012-10-17'
Statement:
- Effect: Allow
Action:
- logs:CreateLogGroup
- logs:CreateLogStream
- logs:PutLogEvents
Resource: arn:aws:logs:*:*:*
- Effect: Allow
Action:
- ec2:DescribeImages
Resource: '*'
# AMIInfoFunction - Look up an AMI based on a NameFilter
# This AWS Lambda function is used to look up an Amazon EC2 AMI based
# on a name filter. An example of a name filter would be:
#
# amzn2-ami-hvm\*ebs
#
# After looking up the names of all images that satify the filter,
# they are sorted in reverse by date/time stamp and the first AMI
# ID (which corresponds to the newest AMI) is returned.
#
# Using a Lambda function makes it possible to look up the AMI
# dynamically. THe alternative would be to create a static map.
#
# Some enhancements could be made here, for example filtering out
# beta releases.
AMIInfoFunction:
Type: AWS::Lambda::Function
Properties:
Description: 'Look up an AMI based on a filter'
Handler: index.handler
MemorySize: 128
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: 'python3.6'
Timeout: 30
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-amilambda' ]]
- Key: Project
Value: !Ref ProjectTag
Code:
ZipFile: |
import json
import boto3
import cfnresponse
def handler(event, context):
if event['RequestType'] == 'Delete':
responseData = {}
cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData)
return
ec2=boto3.client('ec2')
imageDescriptions=ec2.describe_images(
Owners=['amazon'],
Filters=[
{'Name': 'name', 'Values': [event['ResourceProperties']['NameFilter']]}
],
)
if len(imageDescriptions) == 0:
responseData = {}
cfnresponse.send(event, context, cfnresponse.FAILED)
else:
amiNames = sorted(imageDescriptions['Images'],
key=lambda x: x['CreationDate'],
reverse=True)
responseData = {}
responseData['Id'] = amiNames[0]['ImageId']
cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData)
return
# AMIInfo - The AWS Lambda-backed resource for looking up an Amazon EC2 AMI
#
# Parameters
#
# ServiceToken - a pointer to the AWS Lambda function
# NameFilter - the name filter to pass to the describe_images API
AMIInfo:
Type: Custom::AMIInfo
Properties:
ServiceToken: !GetAtt AMIInfoFunction.Arn
NameFilter: 'amzn2-ami-hvm*gp2'
# RandomStrFunction - Generate a string of random characters
#
# This AWS Lambda function is used to generate a random string
# of letters. We'll use the Python string module to do this.
# You can change the composition of the string by changing the
# methods that are used.
RandomStrFunction:
Type: AWS::Lambda::Function
Properties:
Description: 'Generate a random string of characters'
Handler: index.handler
MemorySize: 128
Role: !GetAtt LambdaExecutionRole.Arn
Runtime: 'python3.6'
Timeout: 30
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, 'rndstrlambda' ]]
- Key: Project
Value: !Ref ProjectTag
Code:
ZipFile: |
import json
import boto3
import cfnresponse
import string
import random
def handler(event, context):
if event['RequestType'] == 'Delete':
responseData = {}
cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData)
return
StringLength=int(event['ResourceProperties']['StringLength'])
if StringLength <= 0:
responseData = {}
cfnresponse.send(event, context, cfnresponse.FAILED)
else:
responseData = {}
chars=string.ascii_letters # change this to use other kinds of characters
responseData['RandomString'] = ''.join(random.choice(chars) for _ in range(StringLength))
cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData)
return
# DBMasterUser - The AWS Lambda-backed resource for generating a random username
#
# Parameters
#
# ServiceToken - a pointer to the AWS Lambda function
# StringLength - the length of the random string to generate
DBMasterUser:
Type: Custom::DBMasterUser
Properties:
ServiceToken: !GetAtt RandomStrFunction.Arn
StringLength: '16'
# DBMasterPassword - The AWS Lambda-backed resource for generating a random password
#
# Parameters
#
# ServiceToken - a pointer to the AWS Lambda function
# StringLength - the length of the random string to generate
DBMasterPassword:
Type: Custom::DBMasterPassword
Properties:
ServiceToken: !GetAtt RandomStrFunction.Arn
StringLength: '32'
# DBSG - The security group for the RDS database
DBSG:
Type: AWS::EC2::SecurityGroup
Properties:
GroupDescription: Enable SSH access via port 22
SecurityGroupIngress:
- IpProtocol: tcp
FromPort: !Ref DBPort
ToPort: !Ref DBPort
CidrIp: 0.0.0.0/0
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-dbsg' ]]
- Key: Project
Value: !Ref ProjectTag
VpcId: !Ref VpcName
# DBSubnetGroup - Database subnet group
#
# We need this even for single AZ databases.
DBSubnetGroup:
Type: AWS::RDS::DBSubnetGroup
Properties:
DBSubnetGroupDescription: Subnet group for RDS database
SubnetIds:
- !Ref PubSubnet01
- !Ref PubSubnet02
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-dbsubg' ]]
- Key: Project
Value: !Ref ProjectTag
# DBInstance - Our test database.
#
# Note that this is a public database which makes this tutorial more
# straightforward. Ordinarily, we'd use a private database. We'll keep
# it simple in this demo. To have some randomness with the initial
# password, we'll use the resource ID for the database security group
# as the initial password. The password will change after the first
# rotation.
DBInstance:
Type: AWS::RDS::DBInstance
DependsOn: VpcIgwAttachment
DeletionPolicy: Delete
Properties:
AllocatedStorage: 5
AllowMajorVersionUpgrade: false
AutoMinorVersionUpgrade: true
AvailabilityZone: !Ref AZName01
BackupRetentionPeriod: 0
DBInstanceClass: db.t2.micro
DBName: !Ref DBName
DBSubnetGroupName: !Ref DBSubnetGroup
Engine: 'mysql'
EngineVersion: '5.7'
MasterUsername: !GetAtt DBMasterUser.RandomString
MasterUserPassword: !GetAtt DBMasterPassword.RandomString
MultiAZ: false
Port: !Ref DBPort
PubliclyAccessible: true
StorageType: gp2
Tags:
- Key: Name
Value: !Join [ '', [ Ref: NamePrefix, '-db' ]]
- Key: Project
Value: !Ref ProjectTag
VPCSecurityGroups:
- !Ref DBSG
Outputs:
SecurityNotification:
Description: SecurityNotification
Value: 'SECURITY NOTE: Please delete this stack after you complete this demo!'
BastionIP:
Description: Bastion IP Address
Value: !GetAtt Bastion.PublicIp
DBUser:
Description: RDS MySQL master user
Value: !GetAtt DBMasterUser.RandomString
DBPassword:
Description: RDS MySQL master user initial password
Value: !GetAtt DBMasterPassword.RandomString
DBEndpoint:
Description: RDS MySQL endpoint
Value: !GetAtt DBInstance.Endpoint.Address