- run-instances — AWS CLI 1.14.51 Command Reference
- describe-images — AWS CLI 1.14.51 Command Reference
- create-key-pair — AWS CLI 1.14.51 Command Reference
aws ec2 run-instances help
必須パラメータと予想されるもの
- machine image
- instance type
- public static IP address on/off
- server key
# machine imageの確認 % aws ec2 describe-images \ --image-ids ami-c2680fa4 \ --region ap-northeast-1 # key pairの作成 % aws ec2 create-key-pair \ --key-name otiai10-test01 \ --region ap-northeast-1 # このAPI responseのKeyMaterialをpemファイルにする。 # "\n" を改行にするのを忘れずに(vim参考 :%s/\\n/\r/gc ) % vi otiai10-test01.pem # Instance作成 % aws ec2 run-instances \ --image-id ami-c2680fa4 \ --region ap-northeast-1 \ --key-name otiai10-test01 \ --associate-public-ip-address \ --instance-type t2.micro # 上記のAPI responseにInstanceIdが含まれるので # Instanceのステータス確認 % aws ec2 describe-instances \ --instance-ids i-0206ac48893ced2f5 \ --region ap-northeast-1 # ssh疎通確認 % ssh -i ./otiai10-test01.pem \ ec2-user@54.249.19.62 ssh: connect to host 54.249.19.62 port 22: Operation timed out # あーそういやSecurityGroup忘れてた # SG指定しないと、default Security Groupになっている。 # めんどくさいので、My IPからのAll Trafficを開ける。 # 再度ssh疎通確認 % ssh -i ./otiai10-test01.pem ec2-user@54.249.19.62 @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions 0644 for './otiai10-test01.pem' are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored. Load key "./otiai10-test01.pem": bad permissions Permission denied (publickey,gssapi-keyex,gssapi-with-mic). # あーめんどくせえ # pemファイルのpermission変更 % chmod 600 ./otiai10-test01.pem # ssh疎通確認、三度目の正直 % ssh -i ./otiai10-test01.pem ec2-user@54.249.19.62 __| __|_ ) _| ( / Amazon Linux 2 AMI ___|\___|___| https://aws.amazon.com/amazon-linux-2/ No packages needed for security; 15 packages available Run "sudo yum update" to apply all updates. [ec2-user@ip-172-31-17-228 ~]$ uname -a Linux ip-172-31-17-228.ap-northeast-1.compute.internal 4.9.76-38.79.amzn2.x86_64 #1 SMP Mon Jan 15 23:35:15 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux [ec2-user@ip-172-31-17-228 ~]$ [ec2-user@ip-172-31-17-228 ~]$ exit logout Connection to 54.249.19.62 closed. %
いいですね。掃除しましょう。
# インスタンスの破棄 % aws ec2 terminate-instances \ --instance-ids i-0206ac48893ced2f5 \ --region ap-northeast-1 # key pairの削除 % aws ec2 delete-key-pair \ --key-name otiai10-test01 \ --region ap-northeast-1 # 上記のコマンドにレスポンスが無いので確認 % aws ec2 describe-key-pairs --key-name otiai10-test01 --region ap-northeast-1 An error occurred (InvalidKeyPair.NotFound) when calling the DescribeKeyPairs operation: The key pair 'otiai10-test01' does not exist % % rm otiai10-test01.pem
いいですね。
Amazon Web Servicesではじめる新米プログラマのためのクラウド超入門
- 作者: WINGSプロジェクト阿佐志保
- 出版社/メーカー: 翔泳社
- 発売日: 2016/06/21
- メディア: Kindle版
- この商品を含むブログ (1件) を見る
Amazon Web Services パターン別構築・運用ガイド 改訂第2版
- 作者: 佐々木拓郎
- 出版社/メーカー: SBクリエイティブ
- 発売日: 2018/03/23
- メディア: 単行本
- この商品を含むブログを見る
AWSエキスパート養成読本[Amazon Web Servicesに最適化されたアーキテクチャを手に入れる! ] (Software Design plus)
- 作者: 吉田真吾,今井智明,大瀧隆太,松井基勝,冨永善視,藤原吉規,大栗宗
- 出版社/メーカー: 技術評論社
- 発売日: 2016/02/26
- メディア: 大型本
- この商品を含むブログを見る
追記
regionの指定めんどいので
aws configure set default.region ap-northeast-1