Notice the constraint in the docs when using --db-instance-indentifier:
--db-instance-identifier (string)
The user-supplied instance identifier. If this parameter is specified,
information from only the specific DB instance is returned. This parameter
isn't case-sensitive.
Constraints:
- If supplied, must match the identifier of an existing DBInstance
So you can only use this option if you know the DB in fact exists.
Using queries
To search for a DB that may or may not exist you'll have to use the --query option:
$ aws rds describe-db-instances \
--query 'DBInstances[*].[DBName,DBInstanceIdentifier]' --output text
The DBINstances JSON structure is accessible in the awscli help:
$ aws rds describe-db-instances help --output text
...
...
{
"DBInstances": [
{
"PubliclyAccessible": false,
"MasterUsername": "mymasteruser",
"MonitoringInterval": 0,
"LicenseModel": "general-public-license",
...
...
"DBName": "sample",
...
...
"DBInstanceStatus": "stopped",
"EngineVersion": "5.6.27",
"AvailabilityZone": "us-east-1e",
"StorageType": "standard",
"StorageEncrypted": false,
"DBInstanceClass": "db.t2.micro",
"DbInstancePort": 0,
"DBInstanceIdentifier": "mydbinstance-1"
}
]
}
...
...
Using Filters
Another simple solution for the initial question is, to use the --filters parameter. The query will return either the instance identifier (if the instance exists), or an empty string (if it does not exist):
#!/usr/bin/env bash
DBINSTANCEIDENTIFIER="greatdb"
EXISTINGINSTANCE=$(aws rds describe-db-instances \
--query 'DBInstances[*].[DBInstanceIdentifier]' \
--filters Name=db-instance-id,Values=$DBINSTANCEIDENTIFIER \
--output text \
)
if [ -z $EXISTINGINSTANCE ]
then
echo "instance $DBINSTANCEIDENTIFIER does not exist!"
else
echo "instance $DBINSTANCEIDENTIFIER exists!"
fi
References
- https://docs.aws.amazon.com/cli/latest/reference/rds/describe-db-instances.html
- https://stackoverflow.com/questions/45449174/how-do-i-use-query-parameter-in-aws-rds-describe-db-instances-command
- https://stackoverflow.com/questions/46051538/syntax-for-filters-for-aws-rds-describe-db-instances
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › rds › describe-db-instances.html
describe-db-instances — AWS CLI 2.32.21 Command Reference
These examples will need to be adapted to your terminal’s quoting rules. See Using quotation marks with strings in the AWS CLI User Guide . ... The following describe-db-instances example retrieves details about the specified DB instance. aws rds describe-db-instances \ --db-instance-identifier mydbinstancecf
AWS CLI
awscli.amazonaws.com › v2 › documentation › api › 2.0.33 › reference › rds › describe-db-instances.html
describe-db-instances — AWS CLI 2.0.33 Command Reference
--cli-auto-prompt (boolean) Automatically prompt for CLI input parameters. See ‘aws help’ for descriptions of global parameters. ... The following describe-db-instances example retrieves details about the specified DB instance. aws rds describe-db-instances \ --db-instance-identifier mydbinstancecf
AWS CLI
awscli.amazonaws.com › v2 › documentation › api › 2.9.6 › reference › rds › describe-db-instances.html
describe-db-instances — AWS CLI 2.9.6 Command Reference
See the User Guide for help getting started. ... Returns information about provisioned RDS instances. This API supports pagination. ... This operation can also return information for Amazon Neptune DB instances and Amazon DocumentDB instances. ... describe-db-instances is a paginated operation.
Amazon Web Services
docs.aws.amazon.com › cli › v1 › reference › rds › describe-db-instances.html
describe-db-instances — AWS CLI 1.42.75 Command Reference
These examples will need to be adapted to your terminal’s quoting rules. See Using quotation marks with strings in the AWS CLI User Guide . ... The following describe-db-instances example retrieves details about the specified DB instance. aws rds describe-db-instances \ --db-instance-identifier mydbinstancecf
Amazon Web Services
docs.aws.amazon.com › amazon rds › user guide › code examples for amazon rds using aws sdks › basic examples for amazon rds using aws sdks › actions for amazon rds using aws sdks › use describedbinstances with an aws sdk or cli
Use DescribeDBInstances with an AWS SDK or CLI - Amazon Relational Database Service
Find the complete example and learn how to set up and run in the AWS Code Examples Repository ... suspend fun describeInstances() { RdsClient.fromEnvironment { region = "us-west-2" }.use { rdsClient -> val response = rdsClient.describeDbInstances(DescribeDbInstancesRequest {}) response.dbInstances?.forEach { instance -> println("Instance Identifier is ${instance.dbInstanceIdentifier}") println("The Engine is ${instance.engine}") println("Connection endpoint is ${instance.endpoint?.address}") } } }
AWS
awscli.amazonaws.com › v2 › documentation › api › latest › reference › opsworks › describe-rds-db-instances.html
describe-rds-db-instances — AWS CLI 2.27.41 Command Reference
First time using the AWS CLI? See the User Guide for help getting started. ... Describes Amazon RDS instances. Required Permissions : To use this action, an IAM user must have a Show, Deploy, or Manage permissions level for the stack, or an attached policy that explicitly grants permissions. For more information about user permissions, see Managing User Permissions . This call accepts only one resource-identifying parameter. ... describe-rds-db-instances --stack-id <value> [--rds-db-instance-arns <value>] [--cli-input-json | --cli-input-yaml] [--generate-cli-skeleton <value>] [--debug] [--endp
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › rds › describe-reserved-db-instances.html
describe-reserved-db-instances — AWS CLI 2.32.19 Command Reference
See the User Guide for help getting started. ... Returns information about reserved DB instances for this account, or about a specified reserved DB instance. ... describe-reserved-db-instances is a paginated operation. Multiple API calls may be issued in order to retrieve the entire data set ...
AWS CLI
awscli.amazonaws.com › v2 › documentation › api › 2.8.7 › reference › rds › describe-db-instances.html
describe-db-instances — AWS CLI 2.8.7 Command Reference
These examples will need to be adapted to your terminal’s quoting rules. See Using quotation marks with strings in the AWS CLI User Guide . ... The following describe-db-instances example retrieves details about the specified DB instance. aws rds describe-db-instances \ --db-instance-identifier mydbinstancecf
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › rds
rds — AWS CLI 2.32.23 Command Reference
Amazon RDS is asynchronous, which means that some interfaces might require techniques such as polling or callback functions to determine when a command has been applied. In this reference, the parameter descriptions indicate whether a command is applied immediately, on the next instance reboot, or during the maintenance window.
AWS CLI
awscli.amazonaws.com › v2 › documentation › api › 2.0.34 › reference › rds › describe-db-instances.html
describe-db-instances — AWS CLI 2.0.34 Command Reference
--cli-auto-prompt (boolean) Automatically prompt for CLI input parameters. See ‘aws help’ for descriptions of global parameters. ... The following describe-db-instances example retrieves details about the specified DB instance. aws rds describe-db-instances \ --db-instance-identifier mydbinstancecf
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › rds › describe-db-instance-automated-backups.html
describe-db-instance-automated-backups — AWS CLI 2.32.3 Command Reference
See Using quotation marks with strings in the AWS CLI User Guide . To describe the automated backups for a DB instance · The following describe-db-instance-automated-backups example displays details about the automated backups for the specified DB instance. The details include replicated automated backups in other AWS Regions. aws rds describe-db-instance-automated-backups \ --db-instance-identifier new-orcl-db
AWS CLI
awscli.amazonaws.com › v2 › documentation › api › 2.0.33 › reference › opsworks › describe-rds-db-instances.html
describe-rds-db-instances — AWS CLI 2.0.33 Command Reference
--cli-auto-prompt (boolean) Automatically prompt for CLI input parameters. See ‘aws help’ for descriptions of global parameters. To describe a stack’s registered Amazon RDS instances · The following example describes the Amazon RDS instances registered with a specified stack. aws opsworks --region us-east-1 describe-rds-db-instances --stack-id d72553d4-8727-448c-9b00-f024f0ba1b06
Amazon Web Services
docs.aws.amazon.com › amazon rds › user guide › monitoring metrics in an amazon rds instance › viewing instance status
Viewing instance status - Amazon Relational Database Service
To view just the status of all the DB instances, use the following query in AWS CLI. aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceIdentifier,DBInstanceStatus]' --output table
Top answer 1 of 3
3
You can do something like this:
aws rds describe-db-instances --query 'DBInstances[].DBInstanceStatus[]'
output:
[
"available"
]
2 of 3
1
Use --query instead of --filters:
something like:
aws rds describe-db-instances --query '...'
https://docs.aws.amazon.com/cli/latest/userguide/cli-usage-filter.html
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › rds › describe-orderable-db-instance-options.html
describe-orderable-db-instance-options — AWS CLI 2.32.11 Command Reference
describe-orderable-db-instance-options --engine <value> [--engine-version <value>] [--db-instance-class <value>] [--license-model <value>] [--availability-zone-group <value>] [--vpc | --no-vpc] [--filters <value>] [--cli-input-json | --cli-input-yaml] [--starting-token <value>] [--page-size <value>] [--max-items <value>] [--generate-cli-skeleton <value>] [--debug] [--endpoint-url <value>] [--no-verify-ssl] [--no-paginate] [--output <value>] [--query <value>] [--profile <value>] [--region <value>] [--version <value>] [--color <value>] [--no-sign-request] [--ca-bundle <value>] [--cli-read-timeou
Dba-ninja
dba-ninja.com › 2022 › 09 › aws-cli-cheatsheet.html
AWS CLI Cheatsheet - RDS, AWS Backup , DMS, IAM, Security Token Service,KMS,EC2, DynamoDB,VPC,Aurora, Aurora Global,RESOURCEGROUPSTAGGINGAPI,DocumentDB,CloudTrail
--List rds Instance with the mysql. Return DB InstanceIdentifier · aws rds describe-db-instances --query "DBInstances[?starts_with(Engine,'mysql')==`true`].DBInstanceIdentifier"
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › rds › describe-db-clusters.html
describe-db-clusters — AWS CLI 2.32.18 Command Reference
These examples will need to be adapted to your terminal’s quoting rules. See Using quotation marks with strings in the AWS CLI User Guide . ... The following describe-db-clusters example retrieves the details of the specified DB cluster. aws rds describe-db-clusters \ --db-cluster-identifier mydbcluster
Amazon Web Services
docs.aws.amazon.com › cli › latest › reference › rds › describe-db-snapshots.html
describe-db-snapshots — AWS CLI 2.32.15 Command Reference
See Using quotation marks with strings in the AWS CLI User Guide . Example 1: To describe a DB snapshot for a DB instance · The following describe-db-snapshots example retrieves the details of a DB snapshot for a DB instance. aws rds describe-db-snapshots \ --db-snapshot-identifier mydbsnapshot