こんにちは。AWS CLIが好きな福島です。
今回は、AWS CLIで全Route TableのRoute情報を取得したいなと思い、試してみたため、 その内容をブログに記載いたします。
実行環境
今回、コマンドを実行した環境は、以下の通りとなります。
(本記事でご紹介しているコマンドの中には、Linuxのコマンドを利用している箇所があります。)
# uname -a Linux LAPTOP-CNM26HN6 4.4.0-18362-Microsoft #1049-Microsoft Thu Aug 14 12:01:00 PST 2020 x86_64 x86_64 x86_64 GNU/Linux #
ポイント
出力するターゲットは、以下のみになります。
①GatewayId
②VpcPeeringConnectionId
③TransitGatewayId
④NetworkInterfaceId
⑤DestinationPrefixListId
⑥InstanceIdCSVFILE変数に定義したファイルに出力します。
結論
以下のコマンドで取得できます。
CSVFILE=route-table.csv;\ echo "RouteTableId,DestinationCidrBlock,GatewayId,NatGatewayId,VpcPeeringConnectionId,TransitGatewayId,NetworkInterfaceId,DestinationPrefixListId,InstanceId,State" > ${CSVFILE};\ aws ec2 describe-route-tables --query "RouteTables[].[RouteTableId,Routes[].[DestinationCidrBlock,GatewayId,NatGatewayId,VpcPeeringConnectionId,TransitGatewayId,NetworkInterfaceId,DestinationPrefixListId,InstanceId,State]]" --output text | \ tr "\t" "," | sed -e 's/^1/,1/g' -e 's/^None/,None/g' -e 's/^0/,0/g' >> ${CSVFILE}
- 実行結果
おわりに
今回は、Route Tableを取得する方法を紹介いたしました。 どなたかのお役に立てれば幸いです。