Table of Contents
AWS MySQL RDS Database Creation using AWSCLI
We have a well organized & powerful AWS CLI and CLI commands. Using AWS client and few lines of codes, we can create the AWS MySQL RDS instance. Why do we need AWS MySQL RDS Database Creation using AWSCLI commands? It will be an extra effort for AWS Admin to write and maintenance the MySQL RDS code. Think about a scenario where you have to build hundreds of MySQL RDS instances in fly with different configurations in may other regions. It will be a tedious task for admin to keep doing the same thing, again and again, a hundred times and chances are that we encounter some human-made mistakes. Using AWSCLI scripts you can provision any AWS services easily with few simple codes. In this post, I will show you step by step approach to create an AWS MySQL RDS Instance from AWSCLI.
Prerequisites
1. AWSCLI Configured. How to install it? see this link (AWS Documentation)
2. AWS Access Key ID
3. AWS Secret Access Key
#1. How to configure AWSCLI
➜ ~ aws configure
AWS Access Key ID [****************xxxxx]: XXXXXXXXXXXXXX
AWS Secret Access Key [****************xxxxx]: XXXXXXXXXXXXXXXXXXXXXXX
Default region name [us-east-1]:
Default output format [json]:
#2. Run following command from AWS command sysetax
--create database aws rds create-db-instance \ --db-instance-identifier mytstdb \ --db-instance-class db.t3.small \ --db-name mytstdb \ --engine mysql \ --master-username root \ --master-user-password macmac123 \ --allocated-storage 20 \ --backup-retention-period 3
#3. Query the Database creation status
aws rds describe-db-instances
#4. Query the Database parameters like DB instance name, Endpoint, etc.
aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceArn,DBInstanceIdentifier,DBInstanceClass,Endpoint]'
#5. How to Delete AWS MySQL RDS instance
aws rds delete-db-instance \ --db-instance-identifier mytstdb \ --final-db-snapshot-identifier test-instance-final-snap
Expected log:
➜ ~ aws rds delete-db-instance \ --db-instance-identifier mytstdb \ --final-db-snapshot-identifier test-instance-final-snap { "DBInstance": { "PubliclyAccessible": true, "MasterUsername": "root", "MonitoringInterval": 0, "LicenseModel": "general-public-license", "VpcSecurityGroups": [ { "Status": "active", "VpcSecurityGroupId": "sg-XXXXXXXXXXXXXX" } ], "InstanceCreateTime": "2020-03-16T08:50:12.050Z", "CopyTagsToSnapshot": false, "OptionGroupMemberships": [ { "Status": "in-sync", "OptionGroupName": "default:mysql-5-7" } ], "PendingModifiedValues": {}, "Engine": "mysql", "MultiAZ": false, "LatestRestorableTime": "2020-03-16T09:20:00Z", "DBSecurityGroups": [], "DBParameterGroups": [ { "DBParameterGroupName": "default.mysql5.7", "ParameterApplyStatus": "in-sync" } ], "PerformanceInsightsEnabled": false, "AutoMinorVersionUpgrade": true, "PreferredBackupWindow": "06:03-06:33", "DBSubnetGroup": { "Subnets": [ { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-9b451094", "SubnetAvailabilityZone": { "Name": "us-east-1f" } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-09871927", "SubnetAvailabilityZone": { "Name": "us-east-1c" } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-f887149f", "SubnetAvailabilityZone": { "Name": "us-east-1b" } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-691f3c23", "SubnetAvailabilityZone": { "Name": "us-east-1d" } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-d6bd218a", "SubnetAvailabilityZone": { "Name": "us-east-1a" } }, { "SubnetStatus": "Active", "SubnetIdentifier": "subnet-4671d678", "SubnetAvailabilityZone": { "Name": "us-east-1e" } } ], "DBSubnetGroupName": "default", "VpcId": "vpc-26eb445c", "DBSubnetGroupDescription": "default", "SubnetGroupStatus": "Complete" }, "ReadReplicaDBInstanceIdentifiers": [], "AllocatedStorage": 20, "DBInstanceArn": "arn:aws:rds:us-east-1:xxxxxxxxxxxxxx:db:mytstdb", "BackupRetentionPeriod": 3, "DBName": "mytstdb", "PreferredMaintenanceWindow": "sun:04:47-sun:05:17", "Endpoint": { "HostedZoneId": "XXXXXXXXXXXXXX", "Port": 3306, "Address": "xxxxxxxxxx.xxxxxxxx.us-east-1.rds.amazonaws.com" }, "DBInstanceStatus": "deleting", "IAMDatabaseAuthenticationEnabled": false, "EngineVersion": "5.7.22", "DeletionProtection": false, "AvailabilityZone": "us-east-1a", "DomainMemberships": [], "StorageType": "gp2", "DbiResourceId": "db-XXXXXXXXXXXXXX", "CACertificateIdentifier": "rds-ca-2019", "StorageEncrypted": false, "AssociatedRoles": [], "DBInstanceClass": "db.t3.small", "DbInstancePort": 0, "DBInstanceIdentifier": "mytstdb" } }
Please try and let me know by comments if you have any questions.
Share and Like our Facebook Page
Read more
How to Become Oracle apps DBA?
What does DBA mean?
150 Oracle DBA Interview Questions
Top 5 Future Technologies for Database Administrators (DBA) to learn in 2020
Top 5 Software Technology Trends in 2020 List