LoginSignup
1
1

More than 3 years have passed since last update.

AWS CLIでAMIリージョン間コピーを行うコマンド

Posted at

AWS CLIの初期設定は終わっているものとします。

EC2:インスタンスID確認コマンド

まずはAMIを作成するEC2インスタンスを確認。

タグ:Name、値がMyInstanceのインスタンスの情報を取得する場合

aws ec2 describe-instances --filters "Name=tag:Name,Values=MyInstance"

インスタンスIDを指定して取得する場合

aws ec2 describe-instances --instance-ids {instance-id}

AMI作成コマンド

aws ec2 create-image --instance-id {instanceID} --name {ami-name} --description {description} --reboot

{ami-name}は任意のAMI名。
AMI作成時はデータの整合性を保証するために再起動を行うのがデフォルトの動きになっている。--no-rebootを指定すると再起動しないが、データの整合性は保証されない。
コマンド実行すると新しいAMIのIDが返ってくる。

AMIにタグを作る

aws ec2 create-tags --resources {ami-id} --tags Key={key-name},Value={key-value}

AMIリージョン間コピー

aws ec2 copy-image --source-image-id {ami-id} --source-region {source-region-name} --region {region-name} --name {ami-name}

コマンドを実行すると新しいAMIのIDが返ってくる。

AMI一覧確認コマンド

自分で作成したAMIの一覧

aws ec2 describe-images --owners self

AMI削除コマンド

aws ec2 deregister-image --image-id {ami-id}

補足

別リージョンのAMIを操作する場合はコマンドに--region {RegionName} を付加しないとエラーとなる(指定しない場合aws configureで設定したデフォルトリージョンとなるため)。

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