3.3.3. Managing a RHEL VM on AWS by using the command line


You can use the Amazon Web Services (AWS) command line interface awscli2 utility to manage a Red Hat Enterprise Linux (RHEL) Elastic Cloud Compute (EC2) VM on AWS through the command line. You can import a RHEL EC2 image snapshot, create an Amazon Machine Image (AMI), launch, and connect to a RHEL EC2 instance.

Prerequisites

  • You have created a Red Hat account.
  • You have signed up and set up an AWS account.
  • You have installed the awscli2 package and configured AWS credentials for your account.

Procedure

  1. Use the vmimport role:

    $ aws iam create-role --role-name vmimport \
    --assume-role-policy-document file://<example_vmimport_trust_policy_file>
  2. Embed an inline policy document by using the vmimport role policy file:

    $ aws iam put-role-policy --role-name vmimport \
    --policy-name vmimport-access \
    --policy-document file://<example_vmimport_role_policy_file>

    Also, you can grant VM Import/Export permissions by creating an IAM role (often named vmimport) with a trust policy for vmie.amazonaws.com and attaching the JSON policy from the AWS guide.

  3. Import RHEL image as a snapshot:

    $ aws ec2 import-snapshot --disk-container file://<example_containers_json_file>
  4. Confirm that the snapshot import finished successfully with the completed status:

    $ aws ec2 describe-import-snapshot-tasks --import-task-ids <example_import_task_id>

    You can import a RHEL VM image from Amazon S3 as a snapshot to Amazon EC2. Prepare a <example_containers_json_file> file that points to your S3 bucket and object key, then start the import and monitor the task ID that the command returns.

  5. Register a RHEL AMI from the completed snapshot:

    $ aws ec2 register-image \
    --name <example_rhel_custom_ami_name> \
    --architecture x86_64 \
    --virtualization-type hvm \
    --root-device-name /dev/sda1 \
    --block-device-mappings "[{\"DeviceName\": \"/dev/sda1\",\"Ebs\": {\"SnapshotId\": \"<example_snapshot_id>\"}}]" \
    --ena-support
  6. Create a key pair for the RHEL EC2 instance:

    $ aws ec2 create-key-pair --key-name <example_key_pair_name> \
    --query 'KeyMaterial' --output text > <example_key_file>.pem

    This key pair is per region and save a .pem file.

  7. Restrict permissions on the key file:

    $ chmod 400 <example_key>.pem
  8. Launch a RHEL EC2 instance from the registered AMI:

    $ aws ec2 run-instances \
    --image-id <example_registered_ami_id> \
    --instance-type <example_instance_type> \
    --key-name <example_key_pair_name>
  9. Connect to the RHEL EC2 instance where the default user is ec2-user:

    $ ssh -i <example_key>.pem ec2-user@<instance_public_dns_or_ip>

Verification

  • Verify that the snapshot import finished successfully with the completed status:

    $ aws ec2 describe-import-snapshot-tasks --import-task-ids <example_import_task_id>
  • Verify that the AMI is available with the available state:

    $ aws ec2 describe-images --image-ids <example_registered_ami_id>
  • Verify that the instance is running with the running state:

    $ aws ec2 describe-instances --instance-ids <example_instance_id>

    The State.Name value is running when the instance has finished starting.

  • Verify that the SSH connection works:

    $ ssh -i <example_key>.pem ec2-user@<instance_public_dns_or_ip> 'echo connected'
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 문서 정보

Legal Notice

Theme

© 2026 Red Hat
맨 위로 이동