'Create RDS DB Cluster With Latest Engine Version

From the doc https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_CreateDBCluster.html, CreateDBCluster you can specify a engine version and this field is not required. Will it automatically pick up the latest version if the field is not set? If not, how could I know which version is the latest during db cluster creation?



Solution 1:[1]

Q: What happens if you omit the engine version?

If you do not specify the EngineVersion, then the "default" version is used. For example, at this time, May 2022, the latest is 13.6 but default is 13.4. So, to obtain a reasonably recent and stable version, you can leave the parameter out:

aws rds create-db-cluster --db-cluster-identifier mynewcluster001-cli-demo --master-username postgres --master-user-password YOUR_PASSWORD --engine aurora-postgresql

  • Note 1: The code above doesn't include any parameter groups or security groups. It will use the default for all these values.
  • Note 2: You can run these examples using the AWS Cloud Console.

Q: How can I determine the latest version of an RDS engine?

Approach 1 (shortest):

aws rds describe-db-engine-versions --engine aurora-postgresql --query 'max(DBEngineVersions[*].EngineVersion)'

Returns: 13.6

Documentation is here.

Approach 2 (uses scripting):

aws rds describe-db-engine-versions --engine aurora-postgresql --query 'DBEngineVersions[*].EngineVersion' | grep -o -E '[0-9.]+' | sort -r | head -1
Returns: 13.6

You can capture that value and use it when you create the cluster. (Or, if using the Java library instead, parse the JSON result from DescribeDbEngineVersions.)

To explain the 2nd approach above:

  • grep -o -E '[0-9.]+' Removes all characters except numbers and "."
  • sort -r Sorts the lines. "-r" puts it in reverse order.
  • head -1 This returns the first line.

Keep in mind, there are other ways to do this. I chose to share 2 approaches that I generally find handy for parsing with the AWS CLI.

How it works: Listing all versions

For a list of all valid engine versions, use the DescribeDBEngineVersions action. https://docs.aws.amazon.com/AmazonRDS/latest/APIReference/API_DescribeDBEngineVersions.html

Basic example which returns JSON array of versions: aws rds describe-db-engine-versions --engine aurora-postgresql --query 'DBEngineVersions[*].EngineVersion'

Returns:

[
    "10.14",
    "10.14",
    "10.16",
    "10.17",
    "10.18",
    "10.19",
    "10.20",
    "11.9",
    "11.11",
    "11.12",
    "11.13",
    "11.14",
    "11.15",
    "12.4",
    "12.6",
    "12.7",
    "12.8",
    "12.9",
    "12.10",
    "13.3",
    "13.4",
    "13.5",
    "13.6"
]

Finding the latest "upgradeable" version

Technically speaking, if you're using this to update a server, the latest version may not be the latest one available for upgrade. To be accurate, you'd need to parse the JSON tree from DescribeDBEngineVersions for your current engine version.

However, if you're confident you're on a recent version, here is a script to find the highest version available for upgrades: aws rds describe-db-engine-versions --engine aurora-postgresql --query 'DBEngineVersions[*].ValidUpgradeTarget[*].EngineVersion' | grep -o -E '[0-9.]+' | sort -r | head -1

Solution 2:[2]

From here

You can specify any currently supported MySQL version when creating a new DB instance. You can specify the major version (such as MySQL 5.7), and any supported minor version for the specified major version. If no version is specified, Amazon RDS defaults to a supported version, typically the most recent version. If a major version is specified but a minor version is not, Amazon RDS defaults to a recent release of the major version you have specified.

You can also find out what it will use if you don't specify anything

To see a list of supported versions, as well as defaults for newly created DB instances, use the describe-db-engine-versions AWS CLI command.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Dan M