labunix's blog

labunixのラボUnix

awscliと組み合わせて使う、長くなるbashスクリプトをコマンド化してみた。

■awscliと組み合わせて使う、長くなるbashスクリプトをコマンド化してみた。
 ローカルのdebianとAWS CloudShellで動くように、以下のバージョンでテストした。

 ※甘いチェックしかしていません。
  どちらもAWS CLIの認証やIAMは設定されている前提でのスクリプトです。

$ lsb_release -d
Description:	Debian GNU/Linux 10 (buster)

$ aws --version
aws-cli/1.16.113 Python/3.7.3 Linux/4.19.0-13-amd64 botocore/1.12.103

$ tail -n 1 /etc/system-release
Amazon Linux release 2 (Karoo)

$ aws --version
aws-cli/2.0.58 Python/3.7.3 Linux/4.14.209-160.335.amzn2.x86_64 exec-env/CloudShell exe/x86_64.amzn.2

■AWS CloudShell等、gitから落とす際は以下のようにする。

$ git clone https://github.com/labunix/aws
$ cd aws

■「scope=AWS」のポリシー検索については以下を参照

 ユーザやグループに適用する前にAWSが用意するポリシー名を検索してみる。
 https://labunix.hateblo.jp/entry/20201223/1608723093

$ ./aws-policy-search . | wc -l
783

■「./aws-ssh-codecommit-init」については以下を参照

 AWS CodeCommitをAWS CLIから設定してみる。
 https://labunix.hateblo.jp/entry/20210106/1609935083

$ ./aws-ssh-codecommit-init 
Usage: ./aws-ssh-codecommit-init [aws-iam-user-name]

■「./aws-subcmd-list」でhelpから「AVAILABLE SERVICES」以降のサブコマンドを抽出する。
 「^A」はaws-cli/1用、「AVAI」はaws-cli/2用の検索条件。

$ ./aws-subcmd-list
Usage: ./aws-subcmd-list [aws subcmd]

$ ./aws-subcmd-list aws | grep iam
iam

$ ./aws-subcmd-list aws iam | grep list-role
list-role-policies
list-role-tags
list-roles

■「./aws-region-search」で、どのリージョンを使っているかを一覧にする
 「aws-region.txt」を新規作成、または日付を跨いだら再作成する。
 w3mが使えないのでcurlを使うように書き直した。

$ ./aws-region-search 
Usage  : ./aws-region-search "[aws-cli]" jq-entry
Example: ./aws-region-search "aws codecommit list-repositories" .repositories[].repositoryName

$ ./aws-region-search "aws codecommit list-repositories" .repositories[].repositoryName
[us-east-2]
MyDemoRepo
[us-east-1]
[us-west-1]
[us-west-2]
[af-south-1]
Could not connect to the endpoint URL: "https://codecommit.af-south-1.amazonaws.com/"
[ap-east-1]
無効なリージョン
[ap-south-1]
[ap-northeast-3]
Could not connect to the endpoint URL: "https://codecommit.ap-northeast-3.amazonaws.com/"
[ap-northeast-2]
[ap-southeast-1]
[ap-southeast-2]
[ap-northeast-1]
[ca-central-1]
[eu-central-1]
[eu-west-1]
[eu-west-2]
[eu-south-1]
無効なリージョン
[eu-west-3]
[eu-north-1]
[me-south-1]
無効なリージョン
[sa-east-1]