How To Launch Postgres RDS With AWS Command Line Interface (CLI)

Now that we can launch a bootstrapped EC2 (How To Launch EC2 With Bootstrapping in AWS) with AWS CLI, let’s explore how to launch Postgres RDS with AWS CLI. As in the previous post, we can basically code infrastructure and resources in AWS. This is a step toward coding up your entire infrastructure.

This entry is a bonus step from How To Create Your Personal Data Science Computing Environment In AWS. In the post, we have a step to launch Postgres RDS from the management console (How To Launch an RDS Instance In a Specific Subnet). Here, we can use a line of code to do it.

First of all, you need to install AWS CLI and configure it (read the previous post here).

We are going to use two rds commands: create-db-instance (for creating a rds instance) and delete-db-instance (for deleting it).

create-db-instance

The key point here is to specify the VPC security group and DB Subnet group appropriately and set avaliablitiy zone to the second one according to our plan here.

Make sure to include the publicly-accessible value so that you can get the end point to connect to DB from your local machine. As default, Multi AZ is turned off. Postgres engine is the latest one unless you specify the version.

The db-instance-identifier is required. DB instance identifier is an unique id for each RDS. ^ is the line break for Windows. Use \ for Linux.

aws rds create-db-instance
    --db-name mydatahack ^
    --db-instance-identifier mydatahackpgres ^
    --allocated-storage 20 ^
    --db-instance-class db.t2.micro ^
    --engine postgres ^
    --master-username mydatahack ^
    --master-user-password <password> ^
    --publicly-accessible ^
    --vpc-security-group-ids <vpc security group for rds> ^
    --db-subnet-group <subnet group e.g. default-yourvpcid> ^
    --availability-zone <zone 2 according to our plan> ^
    --port 5432

delete-db-instance

Now, let’s delete the RDS instance with AWS CLI. Use DB instance identifier that you specified when you launched the RDS for delete.

You can either include final snapshot or skip it. In the example below, I am skipping the final snapshot. It is usually a good idea to do a snapshot and launch the new RDS from it if you need it later.

aws rds delete-db-instance
    --db-instance-identifier mydatahackpgres ^
    --skip-final-snapshot

Fun!

Git
How to specify which Node version to use in Github Actions

When you want to specify which Node version to use in your Github Actions, you can use actions/setup-node@v2. The alternative way is to use a node container. When you try to use a publicly available node container like runs-on: node:alpine-xx, the pipeline gets stuck in a queue. runs-on is not …

AWS
Using semantic-release with AWS CodePipeline and CodeBuild

Here is the usual pattern of getting the source from a git repository in AWS CodePipeline. In the pipeline, we use AWS CodeStart to connect to a repo and get the source. Then, we pass it to the other stages, like deploy or publish. For some unknown reasons, CodePipeline downloads …

DBA
mysqldump Error: Unknown table ‘COLUMN_STATISTICS’ in information_schema (1109)

mysqldump 8 enabled a new flag called columm-statistics by default. When you have MySQL client above 8 and try to run mysqldump on older MySQL versions, you will get the error below. mysqldump: Couldn’t execute ‘SELECT COLUMN_NAME, JSON_EXTRACT(HISTOGRAM ‘$”number-of-buckets-specified”‘) FROM information_schema.COLUMN_STATISTICS WHERE SCHEMA_NAME = ‘myschema’ AND TABLE_NAME = ‘craue_config_setting’;’: Unknown …