简体   繁体   中英

Parsing aws cli via jq into CSV

AWS CLI output going to jq to parse into CSV.

This works:

aws ec2 describe-network-acls |jq -r '.NetworkAcls[].Entries[] | [.RuleNumber, .Protocol, .Egress, .CidrBlock, .RuleAction] |@csv'

but this does not:

aws ec2 describe-network-acls |jq -r '.NetworkAcls[].VpcId + "," + .NetworkAcls[].NetworkAclId + "," .NetworkAcls[].Entries[] | [.RuleNumber, .Protocol, .Egress, .CidrBlock, .RuleAction]'

jq: error (at :274): Cannot index string with string "NetworkAcls"

You have to be a bit careful about iteration with [] to avoid loops within loops within loops ...

With the following filter:

.NetworkAcls[]
| [.VpcId, .NetworkAclId]
 + (.Entries[] | [.RuleNumber, .Protocol, .Egress, .CidrBlock, .RuleAction])
| @csv

I get:

"vpc-e68f6f8d","acl-b6d916dd",100,"-1",true,"0.0.0.0/0","allow"
"vpc-e68f6f8d","acl-b6d916dd",32767,"-1",true,"0.0.0.0/0","deny"
"vpc-e68f6f8d","acl-b6d916dd",100,"-1",false,"0.0.0.0/0","allow"
"vpc-e68f6f8d","acl-b6d916dd",32767,"-1",false,"0.0.0.0/0","deny"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM