exportVPC_ID=vpc-xxx
exportVPC_CIDR="172.31.0.0/16"exportRDS_NAME=pgsql
exportAWS_DEFAULT_REGION=sudoyuminstall-yjqsudoamazon-linux-extrasinstall-ypostgresql12
SG_NAME=${RDS_NAME}-${RANDOM}awsec2create-security-group\--description${SG_NAME}\--group-name${SG_NAME}\--vpc-id${VPC_ID}exportRDS_SG=$(awsec2describe-security-groups\--filtersName=group-name,Values=${SG_NAME}\Name=vpc-id,Values=${VPC_ID}\--query"SecurityGroups[0].GroupId"--outputtext)echo"RDS security group ID: ${RDS_SG}"awsec2authorize-security-group-ingress\--group-id${RDS_SG}\--protocoltcp\--port5432\--cidr${VPC_CIDR}exportPUBLIC_SUBNETS_ID=$(awsec2describe-subnets\--filters"Name=vpc-id,Values=$VPC_ID"\--query'Subnets[?MapPublicIpOnLaunch==`true`].SubnetId'\--outputjson|jq-c.)# create a db subnet groupawsrdscreate-db-subnet-group\--db-subnet-group-name${RDS_NAME}\--db-subnet-group-description${RDS_NAME}\--subnet-ids${PUBLIC_SUBNETS_ID}# generate a password for RDSexportRDS_PASSWORD="$(date|md5sum|cut-f1-d' ')"echo${RDS_PASSWORD}>~/rds_password
# create RDS Postgresql instanceawsrdscreate-db-instance\--db-instance-identifier${RDS_NAME}\--db-name${RDS_NAME}\--db-instance-classdb.t3.micro\--enginepostgres\--db-subnet-group-name${RDS_NAME}\--vpc-security-group-ids${RDS_SG}\--master-username${RDS_NAME}\--publicly-accessible\--master-user-password${RDS_PASSWORD}\--backup-retention-period0\--allocated-storage20awsrdsdescribe-db-instances\--db-instance-identifier${RDS_NAME}\--query"DBInstances[].DBInstanceStatus"\--outputtext
# get RDS endpointexportRDS_ENDPOINT=$(awsrdsdescribe-db-instances\--db-instance-identifier${RDS_NAME}\--query'DBInstances[0].Endpoint.Address'\--outputtext)echo"RDS endpoint: ${RDS_ENDPOINT}"cat>/tmp/pgsql.sql<<-EoFCREATE TABLE welcome (column1 TEXT);insert into welcome values ('--------------------------');insert into welcome values ('Welcome to the rdsworkshop');insert into welcome values ('Welcome to the rdsworkshop');insert into welcome values ('Welcome to the rdsworkshop');insert into welcome values ('Welcome to the rdsworkshop');insert into welcome values ('Welcome to the rdsworkshop');insert into welcome values ('--------------------------');EoFexportRDS_PASSWORD=$(cat~/rds_password)psqlpostgresql://${RDS_NAME}:${RDS_PASSWORD}@${RDS_ENDPOINT}:5432/${RDS_NAME}-f/tmp/pgsql.sql
right-click & open-in-new-tab: function get-default-vpc
right-click & open-in-new-tab: function create-sg
right-click & open in new tab: function get-subnets
get-default-vpc
VPC_ID=$DEFAULT_VPCVPC_CIDR=$DEFAULT_CIDRcreate-sg${VPC_ID}${VPC_CIDR}echo${SG_ID}get-subnets${VPC_ID}trueecho${SUBNET_IDS}# create a db subnet groupawsrdscreate-db-subnet-group\--db-subnet-group-name${SG_ID}\--db-subnet-group-description${SG_ID}\--subnet-ids${SUBNET_IDS}DB_ADMIN=admin
DB_PASSWORD=admin1234567890
DB_NAME=llm-$(TZ=EAT-8date+%Y%m%d-%H%M%S)awsrdscreate-db-instance\--db-instance-identifier${DB_NAME}\--enginemysql\--db-instance-classdb.r6g.large\--master-username${DB_ADMIN}\--master-user-password${DB_PASSWORD}\--db-subnet-group-name${SG_ID}\--vpc-security-group-ids${SG_ID}\--allocated-storage100awsrdswaitdb-instance-available--db-instance-identifier${DB_NAME}
# in china regionsource_db_arn=arn:aws-cn:rds:cn-northwest-1:123456789012:db:database-1
awsrdscreate-db-instance-read-replica\--db-instance-identifierdatabase-1-rep-from-cnnw1\--regioncn-north-1\--source-regioncn-northwest-1\--source-db-instance-identifier${source_db_arn}\--kms-key-idarn:aws-cn:kms:cn-north-1:123456789012:alias/aws/rds
wget'https://truststore.pki.rds.amazonaws.com/global/global-bundle.pem'# maybe need to change surfix to pemdbhost=xxxx
mysql-h$dbhost--ssl-ca=global-bundle.pem--ssl-mode=VERIFY_IDENTITY-P3306-uadmin-p