1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowershelllでAWS定常作業を時短(主にEC2)

Last updated at Posted at 2019-08-01

##前提

AWSCLI64PY3.msi をインストールする。
awscliのパスを通す※インストーラウィザード経由で、自動に繋がる

aws configure

https://docs.aws.amazon.com/ja_jp/cli/latest/userguide/cli-chap-configure.html
で設定

[2019.8.2追記]

aws s3 ls

で「Access Denied」が表示した際、再度 aws configureの設定を入力すると解消した
設定

##Tips

※以下、冪等性担保の為に、スクリプト修正予定

configで設定したリージョンにあるEC2の情報をPsCustomObjectに格納

 $obj = aws ec2 describe-instances | Out-String |ConvertFrom-Json

###EC2 PublicDNS取得

実証環境で、ElasticIPなどを設定しておらず、起動毎に変わるPublicIPをメモ帳に書く作業が発生した際

$obj.Reservations.Instances.PublicDnsName >> ""D:\workspace\note.txt""

###EC2 一斉開始
戻り値もJSON、runnningコードが16

 aws ec2 start-instances --instance-id  $obj.Reservations.Instances.InstanceId

###EC2 一斉停止

 aws ec2 stop-instances --instance-id  $obj.Reservations.Instances.InstanceId

##参考
http://acoustic-groove2.hatenablog.com/entry/2017/11/25/020824

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?