Skip to content

Provisioning the AWS RDS instance

Jorge Castro edited this page Mar 30, 2022 · 6 revisions
160799043 88e475e5 35bf 4e8f 95f2 4e479764b470

1. Provisioning the RDS instance

Now we are ready to create our AWS RDS instance:

aws rds create-db-instance `
    --db-instance-identifier sakila-aws `
    --db-instance-class db.t2.micro --engine mysql `
    --master-username "admindb" `
    --master-user-password "my-password" `
    --engine-version 8.0.26 `
    --storage-type gp2 `
    --publicly-accessible `
    --allocated-storage 19

The output tells us the status of the RDS instance creation is Creating. Therefore the endpoint address is not available yet. It takes on average 10 minutes for the instance to be on available status

To obtain the endpoint of the RDS DB, this is possible with just calling a describe-db-instances statement. As the output of this command its quite lengthy, to only retrieve the basic information we need such as DBInstanceIdentifier, Endpoint, etc, we can use the --filter or --query options to filter responses. As the --filter option is supported by a limited number of AWS commands and sub-commands, I prefer to use --query. This option can be used with all AWS commands and uses exclusively the JMESPath JSON scripting language.

--query operates in the actual JSON response and does not need support from the AWS API to support on the filtering.

To query out new RDS:

aws rds describe-db-instances `
    --db-instance-identifier sakila-aws `
    --query 'DBInstances[].Endpoint[].Address[]'

In this way we are getting the information we want. However with the help of the db-instance-available command, we could combine the three commands with pipes and ask AWS the following:

"Create my DB, wait until the InstanceStatus becomes Available, then give me the basic information"

aws rds create-db-instance `
    --db-instance-identifier sakila-aws `
    --db-instance-class db.t2.micro `
    --engine mysql `
    --master-username "admindb" `
    --master-user-password "my-password" `
    --engine-version 8.0.26 `
    --storage-type gp2 `
    --publicly-accessible `
    --allocated-storage 20 | `
    aws rds wait db-instance-available `
    --db-instance-identifier sakila-aws | `
    aws rds describe-db-instances `
    --db-instance-identifier sakila-aws `
    --query "DBInstances[*].[Engine,DBInstanceIdentifier,EngineVersion,DBInstanceStatus,`
    Endpoint.Address,AllocatedStorage,DBInstanceClass,MasterUsername,Endpoint.Port]"

Now we have the database access credentials:

  • User: admindb

  • Endpoint: sakila-aws.cxrtws4xiav1.eu-central-1.rds.amazonaws.com

  • Master-password: my-password

1.1. Associate the new parameter-group to the new RDS instance

aws rds modify-db-instance `
    --db-instance-identifier "sakila-aws" `
    --db-parameter-group-name "superuser"

1.2. Obtain Security Group name

aws rds describe-db-security-groups

1.3. Obtaining Security Group ID

aws ec2 describe-security-groups `
    --group-names default `
    --query 'SecurityGroups[*].[GroupId]'

1.4. Add inbound rule to security group

aws ec2 authorize-security-group-ingress `
    --group-id sg-0f0fe8fea19b7b391 `
    --protocol tcp --port 3306 `
    --cidr 52.47.83.107/32

160298679 57d6e001 3c97 4fbc b369 6c4c2fb41449