以下是describe-db-instances
的概要 [--db-instance-identifier <value>]
[--filters <value>]
[--cli-input-json <value>]
[--starting-token <value>]
[--page-size <value>]
[--max-items <value>]
[--generate-cli-skeleton <value>]
我想知道我应该将哪些值用于-db-instance-identifier,--filters,...?
如果我想使用aws rds describe-db-instances --query,我必须在--query中使用哪些值? 下面是我从互联网上获得的示例:这些值来自(DBInstanceArn,Engine,DBInstanceIdentifier in --query)???
aws rds describe-db-instances \
--query 'DBInstances[*].[DBInstanceArn,Engine,DBInstanceIdentifier]' \
--output text
语法是什么
--query 'DBInstances[*].[DBInstanceArn,Engine,DBInstanceIdentifier]'
答案 0 :(得分:4)
大多数aws cli命令都提供--query
参数。它可以帮助您控制命令执行的输出。您可能需要阅读http://docs.aws.amazon.com/cli/latest/userguide/controlling-output.html#controlling-output-filter,其中详细介绍了它的工作原理。
对于aws rds describe-db-instances
(您可以检查doc或运行aws rds describe-db-instances help
以查找输出值),执行该命令将返回一长串属性列表数据库,对于您运行的每个数据库:
{
"DBInstances": [
{
"PubliclyAccessible": true,
"MasterUsername": "TestDB",
"MonitoringInterval": 0,
"LicenseModel": "general-public-license",
"VpcSecurityGroups": [
{
"Status": "active",
"VpcSecurityGroupId": "sg-5a69722b"
}
],
"CopyTagsToSnapshot": false,
"OptionGroupMemberships": [
{
"Status": "in-sync",
"OptionGroupName": "default:mysql-5-6"
}
],
"PendingModifiedValues": {
"MasterUserPassword": "****"
},
"Engine": "mysql",
"MultiAZ": false,
"DBSecurityGroups": [],
"DBParameterGroups": [
{
"DBParameterGroupName": "default.mysql5.6",
"ParameterApplyStatus": "in-sync"
}
],
"AutoMinorVersionUpgrade": false,
"PreferredBackupWindow": "06:52-07:22",
"DBSubnetGroup": {
"Subnets": [
{
"SubnetStatus": "Active",
"SubnetIdentifier": "subnet-50dea718",
"SubnetAvailabilityZone": {
"Name": "us-east-1d"
}
},
{
"SubnetStatus": "Active",
"SubnetIdentifier": "subnet-c5bba9a0",
"SubnetAvailabilityZone": {
"Name": "us-east-1b"
}
},
{
"SubnetStatus": "Active",
"SubnetIdentifier": "subnet-5ff24a05",
"SubnetAvailabilityZone": {
"Name": "us-east-1a"
}
},
{
"SubnetStatus": "Active",
"SubnetIdentifier": "subnet-98a39da4",
"SubnetAvailabilityZone": {
"Name": "us-east-1e"
}
},
{
"SubnetStatus": "Active",
"SubnetIdentifier": "subnet-42b42c4e",
"SubnetAvailabilityZone": {
"Name": "us-east-1f"
}
},
{
"SubnetStatus": "Active",
"SubnetIdentifier": "subnet-4d28a961",
"SubnetAvailabilityZone": {
"Name": "us-east-1c"
}
}
],
"DBSubnetGroupName": "default",
"VpcId": "vpc-1b70fd62",
"DBSubnetGroupDescription": "default",
"SubnetGroupStatus": "Complete"
},
"ReadReplicaDBInstanceIdentifiers": [],
"AllocatedStorage": 5,
"DBInstanceArn": "arn:aws:rds:us-east-1:325979260958:db:testdb",
"BackupRetentionPeriod": 0,
"DBName": "TestDB",
"PreferredMaintenanceWindow": "wed:10:19-wed:10:49",
"DBInstanceStatus": "creating",
"IAMDatabaseAuthenticationEnabled": false,
"EngineVersion": "5.6.35",
"AvailabilityZone": "us-east-1e",
"DomainMemberships": [],
"StorageType": "gp2",
"DbiResourceId": "db-5VK47WZ6OTS5VEA7OJUF4XH5OI",
"CACertificateIdentifier": "rds-ca-2015",
"StorageEncrypted": false,
"DBInstanceClass": "db.t2.micro",
"DbInstancePort": 0,
"DBInstanceIdentifier": "testdb"
}
]
}
您可能对所有这些元素不感兴趣,但想要专门获取列表的子部分。那是您使用--query
参数
我可以通过运行以下内容将元素数量限制为DBInstanceArn
,Engine
和DBInstanceIdentifier
$ aws rds describe-db-instances --query 'DBInstances[*].[DBInstanceArn,Engine,DBInstanceIdentifier]'
[
[
"arn:aws:rds:us-east-1:325979260958:db:testdb",
"mysql",
"testdb"
]
]
query
参数中使用的语法是JMESPath。由于该命令的输出是一个JSon文档,它可以帮助您解析它。