From 97890105ca7c7221126f61610e42534715b94c7f Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 12 Apr 2024 14:17:11 +0000 Subject: [PATCH] minor updates --- dms/serverless/Readme.md | 2 +- dms/serverless/bin/deploy_mysql | 14 ++++ dms/serverless/bin/deploy_postgres | 14 ++++ dms/serverless/cfn/mysql.yaml | 104 +++++++++++++++++++++++++++++ dms/serverless/cfn/postgres.yaml | 104 +++++++++++++++++++++++++++++ 5 files changed, 237 insertions(+), 1 deletion(-) create mode 100755 dms/serverless/bin/deploy_mysql create mode 100755 dms/serverless/bin/deploy_postgres create mode 100644 dms/serverless/cfn/mysql.yaml create mode 100644 dms/serverless/cfn/postgres.yaml diff --git a/dms/serverless/Readme.md b/dms/serverless/Readme.md index ce2901e..2c73ede 100644 --- a/dms/serverless/Readme.md +++ b/dms/serverless/Readme.md @@ -16,7 +16,7 @@ mysql://admin:password@:5432/mydatabase mysql -u admin -ppassword -h database-2.ck6c4llggxsy.us-east-1.rds.amazonaws.com -P 5432 database -psql postgresql://postgres:password@database-2.ck6c4llggxsy.us-east-1.rds.amazonaws.com:3306/mydatabase +psql postgresql://postgres:password@rds-dms-postgres-rdsinstance-ghj0ttbqkmaf.cv1x0r3utzcm.ca-central-1.rds.amazonaws.com:3306/mydatabase diff --git a/dms/serverless/bin/deploy_mysql b/dms/serverless/bin/deploy_mysql new file mode 100755 index 0000000..769ceea --- /dev/null +++ b/dms/serverless/bin/deploy_mysql @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +echo "== deploy rds" + +STACK_NAME="rds-dms-mysql" + +# https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/deploy/index.html +aws cloudformation deploy \ +--template-file cfn/mysql.yaml \ +--capabilities CAPABILITY_NAMED_IAM \ +--no-execute-changeset \ +--parameter-overrides VpcId="vpc-08f0ec02f7471b018" Subnets="subnet-0e0fd31733061237d,subnet-0377c6b172e2951d4,subnet-0d8058cb02f147a86" \ +--region ca-central-1 \ +--stack-name $STACK_NAME diff --git a/dms/serverless/bin/deploy_postgres b/dms/serverless/bin/deploy_postgres new file mode 100755 index 0000000..c2b987a --- /dev/null +++ b/dms/serverless/bin/deploy_postgres @@ -0,0 +1,14 @@ +#!/usr/bin/env bash + +echo "== deploy rds" + +STACK_NAME="rds-dms-postgres" + +# https://awscli.amazonaws.com/v2/documentation/api/latest/reference/cloudformation/deploy/index.html +aws cloudformation deploy \ +--template-file cfn/postgres.yaml \ +--capabilities CAPABILITY_NAMED_IAM \ +--no-execute-changeset \ +--parameter-overrides VpcId="vpc-08f0ec02f7471b018" Subnets="subnet-0e0fd31733061237d,subnet-0377c6b172e2951d4,subnet-0d8058cb02f147a86" \ +--region us-east-1 \ +--stack-name $STACK_NAME diff --git a/dms/serverless/cfn/mysql.yaml b/dms/serverless/cfn/mysql.yaml new file mode 100644 index 0000000..9eac7eb --- /dev/null +++ b/dms/serverless/cfn/mysql.yaml @@ -0,0 +1,104 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: RDS Postgress +Parameters: + VpcId: + Type: String + Username: + Type: String + Default: admin + Password: + Type: String + Default: password + BackupRetentionPeriod: + Type: Number + Default: 0 + InstanceClass: + Type: String + Default: db.t3.micro + Engine: + Type: String + Default: mysql + EngineVersion: + Type: String + Default: 8.0.35 + PubliclyAccessible: + Type: String + AllowedValues: + - true + - false + Default: true + DeletionProtection: + Type: String + AllowedValues: + - true + - false + Default: false + RdsDatabaseName: + Type: String + Default: "mydatabase" + RdsPort: + Type: Number + Default: 3306 + Subnets: + Type: 'List' + Description: A list of subnets for the Auto Scaling group +Resources: + DbSg: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: !Sub "Security Group for RDS Instance" + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: !Ref RdsPort + ToPort: !Ref RdsPort + CidrIp: 0.0.0.0/0 + SecurityGroupEgress: + - IpProtocol: -1 + FromPort: -1 + ToPort: -1 + CidrIp: 0.0.0.0/0 + VpcId: !Ref VpcId + DBSubnetGroup: + Type: AWS::RDS::DBSubnetGroup + Properties: + DBSubnetGroupDescription: "My DB Subnet Group" + SubnetIds: !Ref Subnets + + RdsInstance: + Type: AWS::RDS::DBInstance + DeletionPolicy: 'Delete' + UpdateReplacePolicy: 'Delete' + Properties: + MasterUsername: !Ref Username + MasterUserPassword: !Ref Password + DBSubnetGroupName: !Ref DBSubnetGroup + AllocatedStorage: '20' + AllowMajorVersionUpgrade: true + AutoMinorVersionUpgrade: true + # This should be turned off When using AuthIAM on the Proxy. + Port: !Ref RdsPort + EnableIAMDatabaseAuthentication: false + BackupRetentionPeriod: !Ref BackupRetentionPeriod + DBInstanceClass: !Ref InstanceClass + DBName: !Ref RdsDatabaseName + Engine: !Ref Engine + DeletionProtection: !Ref DeletionProtection + EngineVersion: !Ref EngineVersion + PubliclyAccessible: !Ref PubliclyAccessible + VPCSecurityGroups: + - !GetAtt DbSg.GroupId +Outputs: + StackName: + Value: !Ref AWS::StackName + RdsUsername: + Value: !Ref Username + Export: + Name: !Sub ${AWS::StackName}RdsUsername + RdsPort: + Value: !Ref RdsPort + Export: + Name: !Sub ${AWS::StackName}RdsPort + RdsDatabaseName: + Value: !Ref RdsDatabaseName + Export: + Name: !Sub ${AWS::StackName}RdsDatabaseName \ No newline at end of file diff --git a/dms/serverless/cfn/postgres.yaml b/dms/serverless/cfn/postgres.yaml new file mode 100644 index 0000000..cb3df3d --- /dev/null +++ b/dms/serverless/cfn/postgres.yaml @@ -0,0 +1,104 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: RDS Postgress +Parameters: + VpcId: + Type: String + Username: + Type: String + Default: postgres + Password: + Type: String + Default: password + BackupRetentionPeriod: + Type: Number + Default: 0 + InstanceClass: + Type: String + Default: db.t3.micro + Engine: + Type: String + Default: postgres + EngineVersion: + Type: String + Default: 15.4 + PubliclyAccessible: + Type: String + AllowedValues: + - true + - false + Default: true + DeletionProtection: + Type: String + AllowedValues: + - true + - false + Default: false + RdsDatabaseName: + Type: String + Default: "mydatabase" + RdsPort: + Type: Number + Default: 5432 + Subnets: + Type: 'List' + Description: A list of subnets for the Auto Scaling group +Resources: + DbSg: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: !Sub "Security Group for RDS Instance" + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: !Ref RdsPort + ToPort: !Ref RdsPort + CidrIp: 0.0.0.0/0 + SecurityGroupEgress: + - IpProtocol: -1 + FromPort: -1 + ToPort: -1 + CidrIp: 0.0.0.0/0 + VpcId: !Ref VpcId + DBSubnetGroup: + Type: AWS::RDS::DBSubnetGroup + Properties: + DBSubnetGroupDescription: "My DB Subnet Group" + SubnetIds: !Ref Subnets + + RdsInstance: + Type: AWS::RDS::DBInstance + DeletionPolicy: 'Delete' + UpdateReplacePolicy: 'Delete' + Properties: + MasterUsername: !Ref Username + MasterUserPassword: !Ref Password + DBSubnetGroupName: !Ref DBSubnetGroup + AllocatedStorage: '20' + AllowMajorVersionUpgrade: true + AutoMinorVersionUpgrade: true + # This should be turned off When using AuthIAM on the Proxy. + Port: !Ref RdsPort + EnableIAMDatabaseAuthentication: false + BackupRetentionPeriod: !Ref BackupRetentionPeriod + DBInstanceClass: !Ref InstanceClass + DBName: !Ref RdsDatabaseName + Engine: !Ref Engine + DeletionProtection: !Ref DeletionProtection + EngineVersion: !Ref EngineVersion + PubliclyAccessible: !Ref PubliclyAccessible + VPCSecurityGroups: + - !GetAtt DbSg.GroupId +Outputs: + StackName: + Value: !Ref AWS::StackName + RdsUsername: + Value: !Ref Username + Export: + Name: !Sub ${AWS::StackName}RdsUsername + RdsPort: + Value: !Ref RdsPort + Export: + Name: !Sub ${AWS::StackName}RdsPort + RdsDatabaseName: + Value: !Ref RdsDatabaseName + Export: + Name: !Sub ${AWS::StackName}RdsDatabaseName \ No newline at end of file