AWS コマンドでEC2のAMIを作成/削除する方法

環境
AWS CloudShell

1.コマンドでEC2のAMIを作成する
構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
aws ec2 create-image \
--instance-id インスタンスID \
--name "AMI名" \
--no-reboot
aws ec2 create-image \ --instance-id インスタンスID \ --name "AMI名" \ --no-reboot
aws ec2 create-image \
--instance-id インスタンスID \
--name "AMI名" \
--no-reboot

\(文字コード5c)で改行できます。改行なしの1行でも可能です。

操作例
1).コマンドを作成してCloudShellに貼り付けEnterキーを押します。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ aws ec2 create-image \
--instance-id xxx \
--name "test-ami" \
--no-reboot
$ aws ec2 create-image \ --instance-id xxx \ --name "test-ami" \ --no-reboot
$ aws ec2 create-image \
--instance-id xxx \
--name "test-ami" \
--no-reboot

結果

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
{
"ImageId": "ami-xxx"
}
{ "ImageId": "ami-xxx" }
{
"ImageId": "ami-xxx"
}

2).AMIの一覧で作成したAMIが表示されます。

3).AMIに紐づくSnapShotも作成されます。

2.コマンドでEC2のAMIを削除する
構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
aws ec2 deregister-image --image-id AMI ID
aws ec2 deregister-image --image-id AMI ID
aws ec2 deregister-image --image-id AMI ID

操作例
1).AMIを削除します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ aws ec2 deregister-image --image-id ami-xxx
$ aws ec2 deregister-image --image-id ami-xxx
$ aws ec2 deregister-image --image-id ami-xxx

2).Snap Shotを削除します

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
$ aws ec2 delete-snapshot --snapshot-id snap-xxxx
$ aws ec2 delete-snapshot --snapshot-id snap-xxxx
$ aws ec2 delete-snapshot --snapshot-id snap-xxxx

 

AWS

Posted by arkgame