Last active
April 6, 2020 04:31
-
-
Save bilzard/fb0ed3b9f3b35b4ff6640b55585bacbd to your computer and use it in GitHub Desktop.
各AWSリソースを一覧するシェルスクリプト
This file contains hidden or 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
#!/bin/bash | |
profile=$1 | |
tmp_dir=~/bin | |
elb_tmp=$tmp_dir/elb.tmp | |
alb_tmp=$tmp_dir/alb.tmp | |
elb_tag_tmp=$tmp_dir/elb_tag.tmp | |
alb_tag_tmp=$tmp_dir/alb_tag.tmp | |
export AWS_DEFAULT_PROFILE=$profile | |
echo LoadBalancerName,Type,Tag.Name | |
aws elb describe-load-balancers |\ | |
jq '.LoadBalancerDescriptions[] | [.LoadBalancerName, "classic"] | @csv' -r |\ | |
tr -d '"' |\ | |
sort -t, -k1 > $elb_tmp | |
aws elbv2 describe-load-balancers |\ | |
jq '.LoadBalancers[] | [.LoadBalancerArn, .LoadBalancerName, .Type] | @csv' -r |\ | |
tr -d '"' |\ | |
sort -t, -k1 > $alb_tmp | |
# describe tags for elb | |
elbs=$(cat $elb_tmp | awk -F, '{print $1}' | xargs) | |
aws elb describe-tags --load-balancer-names $elbs |\ | |
jq '.TagDescriptions[] | [ .LoadBalancerName, (.Tags[] | select(.Key == "Name") | .Value ) ] | @csv' -r |\ | |
tr -d '"' |\ | |
sort -t, -k1 > $elb_tag_tmp | |
# describe tags for alb | |
alb_arns=$(cat $alb_tmp | awk -F, '{print $1}' | xargs) | |
aws elbv2 describe-tags --resource-arns $alb_arns |\ | |
jq '.TagDescriptions[] | [ .ResourceArn, (.Tags[] | select(.Key == "Name") | .Value) ] | @csv' -r |\ | |
tr -d '"' |\ | |
sort -t, -k1 > $alb_tag_tmp | |
# join tag name for elb | |
join -t, -11 -21 $elb_tmp $elb_tag_tmp | |
# join tag name for alb | |
join -t, -11 -21 $alb_tmp $alb_tag_tmp | gawk -F, 'BEGIN{OFS=","}{print $2, $3, $4}' | |
# remove tmp files | |
rm $elb_tmp $alb_tmp $elb_tag_tmp $alb_tag_tmp |
This file contains hidden or 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
#!/bin/bash | |
profile=$1 | |
header='.DBInstanceIdentifier,.DBInstanceClass,.MultiAZ' | |
echo $header | |
aws rds describe-db-instances --profile $profile | jq ".DBInstances[] | [$header] | @csv" -r |\ | |
tr -d '"' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment