Print

Importing the OVA for AMI conversion

Before you begin

Procedure

  1. Open an SSH session.
  2. In Host Name (or IP address), type the IP Address of the virtual server instance, and click Open.
  3. Log in to the Linux server, and run the command: aws.
  4. To configure the AWS details, run the command: aws configure, and do the following:
    1. In AWS Access Key ID, type the AWS access key ID.
    2. In AWS Secret Access Key, type the AWS secret access key ID.
    3. In Default region name, type the region name.

      For example: us-west-2.

    4. In Default output format, type text or json.
  5. To check whether the EC2 instance is ready to use, run the command: aws s3 ls.

    The system displays the S3 bucket that you created.

  6. To view the content of the S3 bucket, run the command: aws s3 ls s3://<nameofbucket>.
    noteNote

    If DNS resolution for the VPC is disabled, the execution of the aws s3 ls s3://<nameofbucket> command fails.

  7. To allow importing files into the EC2 instance, create a vmimport role, and attach policies as mentioned in the following sub-steps:
    1. Create a file named trust-policy.json with the following policy:
      { "Version":"2012-10-17", "Statement":[ { "Sid":"", "Effect":"Allow", 
      "Principal":{ "Service":"vmie.amazonaws.com" }, "Action":"sts:AssumeRole", 
      "Condition":{ "StringEquals":{ "sts:ExternalId":"vmimport" } } } ] }
    2. Use the create-role command to create a role named vmimport and give VM Import/Export access to it.

      Ensure that you specify the full path to the location of the trust-policy.json file, and prefix file:// to it:

      aws iam create-role --role-name vmimport --assume-role-policy-document file://trust-policy.json
    3. Create a file named role-policy.json with the following policy:

      Where <your_bucket_name> is the bucket where the OVA is stored:

      {
      "Version":"2012-10-17",
      "Statement":[
      {
      "Effect":"Allow",
      "Action":[
      "s3:ListBucket",
      "s3:GetBucketLocation"
      ],
      "Resource":[
      "arn:aws:s3:::<your_bucket_name>"
      ]
      },
      {
      "Effect":"Allow",
      "Action":[
      "s3:GetObject"
      ],
      "Resource":[
      "arn:aws:s3:::<your_bucket_name>/*"
      ]
      },
      {
      "Effect":"Allow",
      "Action":[
      "ec2:ModifySnapshotAttribute",
      "ec2:CopySnapshot",
      "ec2:RegisterImage",
      "ec2:Describe*"
      ],
      "Resource":"*"
      }
      ]
      }
    4. Use the following put-role-policy command to attach the policy to the role created above.

      Ensure that you specify the full path to the location of the role-policy.json file.

      aws iam put-role-policy --role-name vmimport --policy-name vmimport --policy-document file://role-policy.json
  8. To import the ova for conversion, type the following command:
    aws ec2 import-image --cli-input-json "{ \"Description\": \"<Server OVA>\", \"DiskContainers\": [ { \"Description\": \"<text description of task>\", \"UserBucket\": { \"S3Bucket\": \"<your_bucket_name>\", \"S3Key\" : \"<server.ova>\" } } ]}"

    Ensure to replace appropriate values wherever brackets <> are present in above command.

    The system displays the Status and the ImportTaskId parameters.

  9. To check the status of the import image, run the command: aws ec2 describe-import-image-tasks --cli-input-json "{ \"ImportTaskIds\": [\"<Your_ImportTaskId>\"], \"NextToken\": \"abc\", \"MaxResults\": 10 } "

    Where, ImportTaskId is the one from the output of the Step 8. For example: import-ami-ffmanv5x.

    The conversion process takes up to 30 minutes. You can run the above command repeatedly. When the AMI conversion is successful, the system displays the Status as completed and also displays ImageId.

    In the following example, the process is at the update stage and is 30% complete.

    [ec2-user@ip-10-143-10-81 ~]$ aws ec2 describe-import-image-tasks --cli-input-json "{ \"ImportTaskIds\": [\"import-ami-ffgji45r\"], \"NextToken\": \"abc\", \"MaxResults\": 10 } " IMPORTIMAGETASKS CM-Simplex-07.1.0.0.xxx-aws-001.ova import-ami-ffgji45r 30 active updating

    In the following example, the process is preparing the AMI and is 76% complete.

     IMPORTIMAGETASKS x86_64 CM-Simplex-07.1.0.0.xxx-aws-001.ova import-ami-ffgji45r BYOL Linux 76 active preparing ami

    The output format varies depending on the selection of the text or JSON format on the aws CLI configuration.

    For more details, see "AWS Import your VM as an image" on the AWS website at http://docs.aws.amazon.com/vm-import/latest/userguide/import-vm-image.html.

  10. Sign in to the Amazon Web Services Management console.
  11. Go to Services > Compute, and click EC2.

    The system displays the EC2 Management Console page.

  12. In the left navigation pane, click IMAGES > AMIs.

    You can search the converted AMI with ImageId. The system displays the newly converted AMI ImageId in the AMI ID column.

    You can give an appropriate name for the AMI ImageId.