我可以获取有关cli表输出中Alias记录值的帮助吗?
test.emea.example.com。是别名。
顺便说一句,如果DNS记录是多值的,如何对这些值进行平整和连接
下面是示例:
$ aws route53 list-resource-record-sets --hosted-zone-id Z34XXXXXXXX4EF --query "ResourceRecordSets[?Type=='A']"
[
{
"ResourceRecords": [
{
"Value": "10.189.134.12"
}
],
"Type": "A",
"Name": "dnsforwarder0.emea.example.com.",
"TTL": 300
},
{
"ResourceRecords": [
{
"Value": "10.189.134.47"
}
],
"Type": "A",
"Name": "dnsforwarder1.emea.example.com.",
"TTL": 300
},
{
"ResourceRecords": [
{
"Value": "10.189.134.78"
}
],
"Type": "A",
"Name": "dnsforwarder2.emea.example.com.",
"TTL": 300
},
{
"AliasTarget": {
"HostedZoneId": "Z32O12XQLNTSW2",
"EvaluateTargetHealth": false,
"DNSName": "dualstack.kubernetes-elb-k8fca-prod-emea-1745420721.eu-west-1.elb.amazonaws.com."
},
"Type": "A",
"Name": "test.emea.example.com."
}
]
[Tiger-Pengs-MacBook-Pro:~/aws/aws_fed]
tpeng $ aws route53 list-resource-record-sets --hosted-zone-id Z34XXXXXXXX4EF --query "ResourceRecordSets[?Type=='A'].[Name,Type,ResourceRecords[0].Value]" --output table --color off
-----------------------------------------------------------
| ListResourceRecordSets |
+----------------------------------+----+-----------------+
| dnsforwarder0.emea.example.com. | A | 10.189.134.12 |
| dnsforwarder1.emea.example.com. | A | 10.189.134.47 |
| dnsforwarder2.emea.example.com. | A | 10.189.134.78 |
| test.emea.example.com. | A | None |
+----------------------------------+----+-----------------+
答案 0 :(得分:0)
您可以通过将JMESpath And expression与keys和contains函数结合使用来实现。这样就可以了:
aws route53 list-resource-record-sets --hosted-zone-id Z34XXXXXXXX4EF \
--query 'ResourceRecordSets[?Type==`A` && contains(keys(@), `AliasTarget`)].Name'
答案 1 :(得分:0)
基于John和Alex的想法,我使用联合以及join函数来获取所需的内容。但是,它太冗长了。
$ aws route53 list-resource-record-sets --hosted-zone-id Z34XXXXXXXX4EF --query "[ResourceRecordSets[?Type=='A' && contains(keys(@), 'AliasTarget')].[Name,Type,AliasTarget.DNSName],ResourceRecordSets[?Type=='A' && contains(keys(@), 'ResourceRecords')].[Name,Type,join(', ', ResourceRecords[].Value)]]" --output table
-------------------------------------------------------------------------------------------------------------------------
| ListResourceRecordSets |
+-----------------------------+----+------------------------------------------------------------------------------------+
| test.example.com. | A | dualstack.kubernetes-elb-k8fca-prod-emea-1745420721.eu-west-1.elb.amazonaws.com. |
| dnsforwarder0.example.com. | A | 10.189.134.12 |
| dnsforwarder1.example.com. | A | 10.189.134.47 |
| dnsforwarder2.example.com. | A | 10.189.134.78 |
| privatezone.example.com. | A | 10.20.30.40, 10.10.30.40, 10.30.30.40 |
+-----------------------------+----+------------------------------------------------------------------------------------+