Skip to content

Commit

Permalink
updated aws_info_ec2.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
HariSekhon committed Nov 22, 2024
1 parent b4f4030 commit d38f77c
Showing 1 changed file with 14 additions and 24 deletions.
38 changes: 14 additions & 24 deletions aws/aws_info_ec2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,29 +86,19 @@ for ami_id in "${!ami_map[@]}"; do
s/\"$ami_id\"/\"$ami_name\"/g;"
done

timestamp "Getting list of EC2 instances"
# shellcheck disable=SC2016
json="$(
aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].{
"Name": Tags[?Key==`Name`].Value | [0],
"ID": InstanceId,
"State": State.Name,
"InstanceType": InstanceType,
"AMI": ImageId,
"Architecture": "Architecture",
"PublicDNS": publicDnsName,
"PrivateDNS": PrivateDnsName
}' \
--output json |
jq_debug_pipe_dump
)"

timestamp "Generating CSV output with AMI images IDs resolved to names"
timestamp "Getting list of EC2 instances with translated AMI IDs to Names"
echo >&2
jq -r '
.[][] |
[ .ID, .Name, .State, .InstanceType, .AMI, .Architecture, .PrivateDNS, .PublicDNS ] |
@csv
' <<< "$json" |
# shellcheck disable=SC2016
aws ec2 describe-instances \
--query 'Reservations[*].Instances[*].{
"Name": Tags[?Key==`Name`].Value | [0],
"ID": InstanceId,
"State": State.Name,
"InstanceType": InstanceType,
"AMI": ImageId,
"Architecture": "Architecture",
"PublicDNS": publicDnsName,
"PrivateDNS": PrivateDnsName
}' \
--output table |
sed "$sed_script"

0 comments on commit d38f77c

Please sign in to comment.