This is my JSON output from awscli I want to get xxxxxxxx.cloudfront.net using Origin DomainName example1.com with AWS cli query only. { I know this filtering with jq, awk and cut, grep }.
"DistributionList": {
"Items": [
{
"WebACLId": "",
"Origins": {
"Items": [
{
"OriginPath": "",
"CustomOriginConfig": {
"OriginProtocolPolicy": "http-only",
"HTTPPort": 80,
"HTTPSPort": 443
},
"Id": "DNS for Media Delivery",
"DomainName": "example1.com"
}
],
"Quantity": 1
},
"DomainName": "xxxxxxxx.cloudfront.net",
},
{
"WebACLId": "",
"Origins": {
"Items": [
{
"OriginPath": "",
"CustomOriginConfig": {
"OriginProtocolPolicy": "http-only",
"HTTPPort": 80,
"HTTPSPort": 443
},
"Id": "DNS for Media Delivery",
"DomainName": "example2.com"
}
],
"Quantity": 1
},
"DomainName": "yyyyyyyyyy.cloudfront.net",
},
]
}
As AWS CLI --query
parameter works on top of JMESPath you can build awesome filters.
Answer for your question will be:
--query "DistributionList.Items[].{DomainName: DomainName, OriginDomainName: Origins.Items[0].DomainName}[?contains(OriginDomainName, 'example1.com')] | [0]"
and it will return you:
{
"DomainName": "xxxxxxxx.cloudfront.net",
"OriginDomainName": "example1.com"
}
P.S. Hope it will help someone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With