4
5

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.

OVAファイルをAMIとして取り込む

Posted at

ステップ 3: イメージとして VM をインポートする - VM Import/Export」に基づいて OVA ファイルをアップロードして AMI にする手順をまとめた。

S3 バケットの作成

OVA ファイルをいったん S3 バケットにアップロードする必要があるため、バケットを作成する。

① 名前とリージョンで以下の指定を実施

  • 「バケット名」に任意の文字列を入力
  • 「リージョン」に適切なリージョン(通常は「アジアパシフィック(東京)」を指定
  • 「次へ」ボタンを押下

② プロパティの設定

  • 必要に応じて設定
  • 「次へ」ボタンを押下

③ アクセス許可の設定

  • (「パブリックアクセス許可を管理」を開き「認証済みの AWS ユーザー」の「読み込み」をチェック)
  • 「次へ」ボタンを押下

④ 確認

  • 「バケットを作成」ボタンを押下

awscli のインストール

brew install awscli
aws configure

今回は Mac で作業したので Homebrew でインストール。環境に応じて適宜対応。

サービスロールの作成

ポリシーの作成

cat << "_EOF_" > trust-policy.json
{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Principal": { "Service": "vmie.amazonaws.com" },
         "Action": "sts:AssumeRole",
         "Condition": {
            "StringEquals":{
               "sts:Externalid": "vmimport"
            }
         }
      }
   ]
}
_EOF_
aws iam create-role --role-name vmimport --assume-role-policy-document file://trust-policy.json

create-role コマンドで vmimport というロールを作成する。

ロールへのポリシーのアタッチ

cat << "_EOF_" > role-policy.json
{
   "Version": "2012-10-17",
   "Statement": [
      {
         "Effect": "Allow",
         "Action": [
            "s3:ListBucket",
            "s3:GetBucketLocation"
         ],
         "Resource": [
            "arn:aws:s3:::disk-image-file-bucket"
         ]
      },
      {
         "Effect": "Allow",
         "Action": [
            "s3:GetObject"
         ],
         "Resource": [
            "arn:aws:s3:::disk-image-file-bucket/*"
         ]
      },
      {
         "Effect": "Allow",
         "Action":[
            "ec2:ModifySnapshotAttribute",
            "ec2:CopySnapshot",
            "ec2:RegisterImage",
            "ec2:Describe*"
         ],
         "Resource": "*"
      }
   ]
}
_EOF_
aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document file://role-policy.json

disk-image-file-bucket (2箇所) は適宜変更のこと。
put-role-policy コマンドで上記で作成したロールにポリシーをアタッチする。

OVA ファイルのアップロード

aws s3 cp disk-image-file.ova s3://disk-image-file-bucket/

カレントディレクトリーにある disk-image-file.ova ファイルを disk-image-file-bucket バケットにアップロードする。

OVA ファイルのインポート

cat << "_EOF_" > containers.json
[
  {
    "Description": "OVA Disk Image",
    "Format": "ova",
    "UserBucket": {
        "S3Bucket": "disk-image-file-bucket",
        "S3Key": "disk-image-file.ova"
    }
  }
]
_EOF_
aws ec2 import-image --description "OVA Disk Image" --disk-containers file://containers.json

JSON ファイル内に "Description": があるが、オプションでも --description を指定しないと以下のエラーが出る。

A client error (InvalidParameter) occurred when calling the ImportImage operation: The service role <vmimport> does not exist or does not have sufficient permissions for the service to continue

ステータスの確認

aws ec2 describe-import-image-tasks --import-task-ids import-ami-XXXXXXXX
IMPORTIMAGETASKS	OVA Disk Image	import-ami-XXXXXXXX	2	active	pending
SNAPSHOTDETAILS	0.0	OVA
USERBUCKET	disk-image-file-bucket	disk-image-file.ova
IMPORTIMAGETASKS	OVA Disk Image	import-ami-XXXXXXXX	28	active	converting
SNAPSHOTDETAILS	771973632.0	VMDK
USERBUCKET	disk-image-file-bucket	disk-image-file.ova
IMPORTIMAGETASKS	OVA Disk Image	import-ami-XXXXXXXX	30	active	updating
SNAPSHOTDETAILS	771973632.0	VMDK
USERBUCKET	disk-image-file-bucket	disk-image-file.ova
IMPORTIMAGETASKS	OVA Disk Image	import-ami-XXXXXXXX	37	active	updating
SNAPSHOTDETAILS	771973632.0	VMDK
USERBUCKET	disk-image-file-bucket	disk-image-file.ova
IMPORTIMAGETASKS	x86_64	OVA Disk Image	import-ami-XXXXXXXX	BYOL	Linux	59	active	booting
SNAPSHOTDETAILS	/dev/sda1	771973632.0	VMDK
USERBUCKET	disk-image-file-bucket	disk-image-file.ova
IMPORTIMAGETASKS	x86_64	OVA Disk Image	ami-XXXXXXXX	import-ami-XXXXXXXX	BYOL	Linux	completed
SNAPSHOTDETAILS	/dev/sda1	771973632.0	VMDK	snap-XXXXXXXXXXXXXXXXX
USERBUCKET	disk-image-file-bucket	disk-image-file.ova

watch コマンドを使ってもいいかもしれない。

4
5
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
4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?