@@ -37,6 +37,17 @@ Parameters:
37
37
Type : String
38
38
Description : Location of LADV code ZIP
39
39
Default : https://amazon-dynamodb-labs.com/assets/workshop.zip
40
+ DBLatestAmiId :
41
+ Type : ' AWS::SSM::Parameter::Value<AWS::EC2::Image::Id>'
42
+ Default : ' /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2'
43
+ DbMasterUsername :
44
+ Description : The datbase master user name
45
+ Type : String
46
+ Default : dbuser
47
+ DbMasterPassword :
48
+ Description : The database master password
49
+ Type : String
50
+ Default : m7de4uwt2eG#
40
51
41
52
Metadata :
42
53
AWS::CloudFormation::Interface :
@@ -658,7 +669,7 @@ Resources:
658
669
" if [[ \"$RESULT\" -ne 0 ]]; then",
659
670
" sleep_delay",
660
671
" else",
661
- " /bin/bash /tmp/dynamodbworkshop.sh ${SUB_VERSION} ${AWS::AccountId} ${AWS::Region} \"${WorkshopZIP}\" \"${SUB_REPL_ROLE}\" &&",
672
+ " /bin/bash /tmp/dynamodbworkshop.sh ${SUB_VERSION} ${AWS::AccountId} ${AWS::Region} \"${WorkshopZIP}\" \"${SUB_REPL_ROLE}\" \"${SUB_DB_USER}\" \"${SUB_DB_PASSWORD}\" &&",
662
673
" exit 0",
663
674
" fi",
664
675
"done"
@@ -672,6 +683,8 @@ Resources:
672
683
SUB_USERDATA_URL : !FindInMap [DesignPatterns, options, UserDataURL],
673
684
SUB_VERSION : !FindInMap [DesignPatterns, options, version],
674
685
SUB_REPL_ROLE : !GetAtt ['DDBReplicationRole', 'Arn'],
686
+ SUB_DB_USER : !Ref 'DbMasterUsername',
687
+ SUB_DB_PASSWORD : !Ref 'DbMasterPassword',
675
688
}
676
689
Cloud9BootstrapAssociation :
677
690
Type : AWS::SSM::Association
@@ -716,6 +729,83 @@ Resources:
716
729
Value : Active
717
730
- Key : Environment
718
731
Value : !Ref EnvironmentName
732
+ # ########### RELATIONAL MIGRATION STAGING BUCKET #########
733
+ MigrationS3Bucket :
734
+ Type : AWS::S3::Bucket
735
+ # ##### RELATIONAL MIGRATION MYSQL EC2 PUBLIC INSTANCE ######
736
+ DbSecurityGroup :
737
+ Type : AWS::EC2::SecurityGroup
738
+ Properties :
739
+ GroupDescription : MySQL security group
740
+ SecurityGroupIngress :
741
+ - CidrIp : 172.31.0.0/16
742
+ IpProtocol : tcp
743
+ FromPort : 3306
744
+ ToPort : 3306
745
+ Tags :
746
+ - Key : Name
747
+ Value : MySQL-SecurityGroup
748
+ DBInstanceProfile :
749
+ Type : AWS::IAM::InstanceProfile
750
+ Properties :
751
+ InstanceProfileName : DBInstanceProfile
752
+ Path : /
753
+ Roles :
754
+ - !Ref DBInstanceRole
755
+ DBInstanceRole :
756
+ Type : AWS::IAM::Role
757
+ Properties :
758
+ RoleName : DBInstanceRole
759
+ AssumeRolePolicyDocument :
760
+ Version : 2012-10-17
761
+ Statement :
762
+ -
763
+ Effect : Allow
764
+ Principal :
765
+ Service :
766
+ - ec2.amazonaws.com
767
+ Action :
768
+ - sts:AssumeRole
769
+ Path : /
770
+ ManagedPolicyArns :
771
+ - arn:aws:iam::aws:policy/AmazonS3FullAccess
772
+ - arn:aws:iam::aws:policy/AmazonSSMManagedInstanceCore
773
+ DbInstance :
774
+ Type : AWS::EC2::Instance
775
+ Properties :
776
+ ImageId : !Ref DBLatestAmiId
777
+ InstanceType : !GetAtt Cloud9FindTheInstanceTypeLambda.InstanceType
778
+ SecurityGroupIds :
779
+ - !GetAtt DbSecurityGroup.GroupId
780
+ SubnetId : !GetAtt Cloud9FindTheInstanceTypeLambda.SubnetId
781
+ IamInstanceProfile : !Ref DBInstanceProfile
782
+ BlockDeviceMappings :
783
+ - DeviceName : /dev/xvda
784
+ Ebs :
785
+ VolumeType : gp2
786
+ VolumeSize : 50
787
+ DeleteOnTermination : True
788
+ Encrypted : True
789
+ UserData :
790
+ Fn::Base64 : !Sub |
791
+ # !/bin/bash -ex
792
+ sudo su
793
+ rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023
794
+ rpm -Uvh https://repo.mysql.com/mysql80-community-release-el7-3.noarch.rpm
795
+ yum install -y mysql-community-server
796
+ systemctl enable mysqld
797
+ systemctl start mysqld
798
+ export DbMasterPassword=${DbMasterPassword}
799
+ export DbMasterUsername=${DbMasterUsername}
800
+ mysql -u root "-p$(grep -oP '(?<=root@localhost\ : )\S+' /var/log/mysqld.log)" -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '${DbMasterPassword}'" --connect-expired-password
801
+ mysql -u root "-p${DbMasterPassword}" -e "CREATE USER '${DbMasterUsername}' IDENTIFIED BY '${DbMasterPassword}'"
802
+ mysql -u root "-p${DbMasterPassword}" -e "GRANT ALL PRIVILEGES ON *.* TO '${DbMasterUsername}'"
803
+ mysql -u root "-p${DbMasterPassword}" -e "FLUSH PRIVILEGES"
804
+ mysql -u root "-p${DbMasterPassword}" -e "CREATE DATABASE app_db;"
805
+ Tags :
806
+ - Key : Name
807
+ Value : MySQL-Instance
808
+
719
809
720
810
# ################# OUTPUTS #####################
721
811
Outputs :
@@ -732,6 +822,11 @@ Outputs:
732
822
Value : !Ref Cloud9LogBucket
733
823
Export :
734
824
Name : Cloud9LogBucket
825
+ MigrationS3BucketName :
826
+ Description : S3 Bucket Name
827
+ Value : !Ref MigrationS3Bucket
828
+ Export :
829
+ Name : MigrationS3Bucket
735
830
Cloud9RoleArn :
736
831
Description : Role Arn
737
832
Value : !GetAtt Cloud9Role.Arn
0 commit comments