项目作者: yhidetoshi

项目描述 :
Go言語でaws-sdk-goを活用してオレオレCLI(ore-aws)を作った
高级语言: Go
项目地址: git://github.com/yhidetoshi/go-awscli-tool.git
创建时间: 2017-12-07T03:50:20Z
项目社区:https://github.com/yhidetoshi/go-awscli-tool

开源协议:MIT License

下载


MIT License

Alt Text

go-awscli-tool

  • Go言語でaws-sdk-goを利用してAWSを制御するツールです。(勉強しながら作っています)

main以外のソースコード

コンパイル

  • go buildでファイルをクロスコンパイルする
  • /usr/local/bin等の場所に保存する。(以下は /usr/local/binに ore-aws という名前で配置)
  • macOSとLinux(amd64)とWindows用にクロスコンパイルしたバイナリはこちら

(ex)
$ore-aws -resource=ec2 -profile=stg

使い方(コマンドオプション)

EC2

  1. 一覧
  2. > $ ore-aws -resource=ec2 -profile=<PROFILE>
  3. 起動
  4. > $ ore-aws -resource=ec2 -start -instances=<INSTANCENAME> or <INSTANCEID> -profile=<PROFILE>
  5. 停止
  6. > $ ore-aws -resource=ec2 -stop -instances=<INSTANCENAME> or <INSTANCEID> -profile=<PROFILE>
  7. 削除
  8. > $ ore-aws -resource=ec2 -terminate -instances=<INSTANCENAME> or <INSTANCEID> -profile=<PROFILE>
  9. インスタンスを 複数同時に操作するときは `,` で区切り複数指定する
  10. AMI焼き
  11. > $ ore-aws -resource=ec2 -ami -aminame=<AMINAME> -instances=<INSTANCENAME> or <INSTANCEID> -profile=<PROFILE>
  12. AMI情報の一覧を取得
  13. > $ ore-aws -resource=ec2 -amilist -profile=<PROFILE>
  14. AMIの削除(解除)
  15. > $ ore-aws -resource=ec2 -deregister -amiid=<ami-id> -profile=<PROFILE>
  16. ElasticIPの一覧をを取得
  17. > $ ore-aws -resource=ec2 -eiplist -profile=<PROFILE>
  18. ElasticIPのリリース
  19. > $ ore-aws -resource=ec2 -deleteeip -allocationid=<ALLOCATIONID> -profile=<PROFILE>
  20. SecurityGroupの一覧を取得
  21. > $ ore-aws -resource=ec2 -sglist -profile=<PROFILE>
  22. SecurityGroupのルール確認(output:json)
  23. > $ ore-aws -resource=ec2 -show -sgid=<GROUPID> -profile=<PROFILE>
  24. AutoScalingグループ一覧の情報を出力(コンソール画面相当)
  25. > $ ore-aws -resource=as -profile=<PROFILE>
  26. AutoScalingグループのインスタンスの`最大`数を変更
  27. > $ ore-aws -resource=as -asg=<GROUP名> -max -num=<NUM> -profile=<PROFILE>
  28. AutoScalingグループのインスタンスの`最小`数を変更
  29. > $ ore-aws -resource=as -asg=<GROUP名> -min -num=<NUM> -profile=<PROFILE>
  30. AutoScalingグループのインスタンスの`希望`数を変更
  31. > $ ore-aws -resource=as -asg=<GROUP名> -desire -num=<NUM> -profile=<PROFILE>

RDS

  1. 一覧
  2. > $ ore-aws -resource=rds -profile=<PROFILE>
  3. 起動
  4. > $ ore-aws -resource=rds -start -instances=<INSTANCENAME> or <INSTANCEID> -profile=<PROFILE>
  5. 停止
  6. > $ ore-aws -resource=rds -stop -instances=<INSTANCENAME> or <INSTANCEID> -profile=<PROFILE>

ELB

  1. 一覧
  2. > $ ore-aws -resource=elb -profile=<PROFILE>
  3. ELBのバックエンドインスタンスを取得
  4. > $ ore-aws -resource=elb -show -elbname=<ELBNAME> -profile=<PROFILE>
  5. ELBにバックエンドインスタンスを登録
  6. > $ ore-aws -resource=elb -register -elbname=<ELBNAME> -instances=<INSTANCEID> -profile=<PROFILE>
  7. ELBにバックエンドインスタンスを解除
  8. > $ ore-aws -resource=elb -deregister -elbname=<ELBNAME> -instances=<INSTANCEID> -profile=<PROFILE>

S3

  1. バケット一覧
  2. > $ ore-aws -resource=s3 -profile=<PROFILE>
  3. バケットのオブジェクト一覧を取得
  4. > $ ore-aws -resource=s3 -show -bucket=<BUCKETNAME> -profile=<PROFILE>
  5. バケットのサイズ取得
  6. > $ ore-aws -resource=s3 -size -bucket=<BUCKETNAME> -profile=<PROFILE>
  7. バケットの削除(条件: bucket is empty)
  8. > $ ore-aws -resource=s3 -deletebucket -bucket=<BUCKETNAME> -profile=<PROFILE>
  9. オブジェクト削除
  10. > $ ore-aws -resource=s3 -deleteobject -bucket=<BUCKETNAME> -object=<FILENAME>
  11. バケット内のオブジェクトを全て削除
  12. > $ ore-aws -resource=s3 -deleteallobject -bucket=<BUCKETNAME> -profile=<PROFILE>
  13. Tokyoリージョン内の全バケットのACLPublic or Privateかを取得
  14. > $ ore-aws -resource=s3 -checkacl -profile=<PROFILE>
  15. Tokyoリージョン内の全バケットサイズを取得
  16. > $ ore-aws -resource=s3 -sizeall -profile=<PROFILE>

Route53

  1. Zone一覧
  2. > $ ore-aws -resource=route53 -profile=<PROFILE>
  3. Zoneid指定のレコード情報取得
  4. > $ ore-aws -resource=route53 -show -zoneid=<ZONEID> -profile=<PROFILE>

Cloudwatch

  1. Billing
  2. > $ ore-aws -resource=cloudwatch -billing -profile=<PROFILE>
  3. Alarm
  4. > $ ore-aws -resource=cloudwatch -profile=<PROFILE>

IAM

  1. ユーザ一覧
  2. > $ ore-aws -resource=iam-user -profile=<PROFILE>
  3. グループ一覧
  4. > $ ore-aws -resource=iam-group -profile=<PROFILE>

1リージョンの全バケットの合計サイズを計算する処理をGoroutineで処理するように変更

  • 一部抜粋
    ```
    wg := new(sync.WaitGroup)
    ch := make(chan int64, len(allBuckets))

wg.Add(len(allBuckets))
for i := 0; i < len(allBuckets); i++ {
buffBucket = &allBuckets[i]
go CalcThreadBucketSize(S3Client, buffBucket, ch, wg)
}

  1. マルチスレッド実行

➜ aws-cli-go git:(master) ✗ ore-aws -resource=s3 -sizeall -profile=infra-stg
+————————-+
| TOTAL SIZE(KIB) |
+————————-+
| 7897247147 |
+————————-+
1.711132秒

  1. シングルスレッド実行

➜ aws-cli-go git:(master) ✗ ore-aws -resource=s3 -sizeall -profile=infra-stg
+————————-+
| TOTAL SIZE(KIB) |
+————————-+
| 7897247147 |
+————————-+
3.277896秒

  1. ### AWS-SDK-Goのドキュメントを読んでいてのメモ
  2. - APIリクエストの必須な引数について
  3. - `type ReleaseAddressInput`

type ReleaseAddressInput struct {

  1. // [EC2-VPC] The allocation ID. Required for EC2-VPC.
  2. AllocationId *string `type:"string"`
  3. // Checks whether you have the required permissions for the action, without
  4. // actually making the request, and provides an error response. If you have
  5. // the required permissions, the error response is DryRunOperation. Otherwise,
  6. // it is UnauthorizedOperation.
  7. DryRun *bool `locationName:"dryRun" type:"boolean"`
  8. // [EC2-Classic] The Elastic IP address. Required for EC2-Classic.
  9. PublicIp *string `type:"string"`
  10. // contains filtered or unexported fields

}
```