Created
November 24, 2017 10:20
-
-
Save palashkulsh/b31ef87f44d382f56a5cf8263e93d5a6 to your computer and use it in GitHub Desktop.
get aws tags of private ip address using aws cli and jq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ip.csv file should have single column of private ip | |
cat ip.csv | xargs -I {} aws ec2 describe-instances --filter Name=private-ip-address,Values={} | jq --arg tag1 "Service" --arg tag2 "Team" '.Reservations[].Instances[] | "\(.PrivateIpAddress) , \(.Tags[]| select(.Key==$tag1) | .Value) , \(.Tags[]| select(.Key==$tag2) | .Value)"' > ip_service_team.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aws ec2 describe-volumes --region=ap-south-2 | jq -r ' .Volumes[] | { volumeId: (.VolumeId), InstanceId: (.Attachments[0].InstanceId // "null"), VolumeType: .VolumeType, Service: (.Tags // [] | map(select(.Key == "Service")) | .[0].Value // "null"), Stack: (.Tags // [] | map(select(.Key == "Stack")) | .[0].Value // "null"), techteam: (.Tags // [] | map(select(.Key == "Techteam")) | .[0].Value // "null"), Size: .Size } | [.volumeId, .InstanceId, .VolumeType, .Service, .Stack, .Size, .techteam] | @csv' > /tmp/volume.csv