본문 바로가기

퍼블릭 클라우드

[draft] AWS CLI를 사용하여 Amazon EC2 AMI를 찾는 방법

728x90

AWS Command Line Interface (CLI)를 사용하여 Amazon EC2 AMI(Amazon Machine Image)를 찾는 방법

AMI 찾기 명령 실행

아래의 명령어를 사용하여 AWS CLI를 통해 AMI를 찾을 수 있습니다.

aws ec2 describe-images --owners self

위의 명령은 현재 계정의 모든 AMI를 조회합니다. 필요에 따라 다른 --owners 값으로 조회 대상을 변경할 수 있습니다. 예를 들어, AWS Marketplace에서 제공하는 AMI를 조회하려면 --owners aws-marketplace를 사용할 수 있습니다.

추가적으로, --filters 옵션을 사용하여 특정 조건에 맞는 AMI를 검색할 수도 있습니다. 예를 들어, 특정 운영체제를 사용하는 AMI를 찾으려면 아래와 같이 명령을 실행할 수 있습니다.

aws ec2 describe-images --owners self --filters "Name=platform,Values=Linux"

필요에 따라 --region 옵션을 사용하여 특정 리전의 AMI를 조회할 수도 있습니다.

Amazon EC2의 AWS CLI 명령을 사용하여 필요에 맞는 Linux AMI만 나열할 수 있습니다

aws ec2 describe-images --owners self amazon
aws ec2 --profile terraform --region us-east-1 \
describe-images --owners self amazon \
--filters "Name=owner-id,Values=137112412989" \
"Name=name,Values=amzn2-ami-kernel-*" \
"Name=virtualization-type,Values=hvm" \
"Name=architecture,Values=x86_64" "Name=root-device-type,Values=ebs" \
--query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]"
[
    [
        "2021-07-07T06:47:18.000Z", 
        "amzn2-ami-kernel-5.10-hvm-2.0.20210701.0-x86_64-ebs", 
        "ami-0995d03909540c08a"
    ], 
    [
        "2021-07-07T06:50:59.000Z", 
        "amzn2-ami-kernel-5.10-hvm-2.0.20210701.0-x86_64-gp2", 
        "ami-06ae2c7d9589ff619"
    ], 
    [
        "2021-07-27T06:19:16.000Z", 
        "amzn2-ami-kernel-5.10-hvm-2.0.20210721.2-x86_64-ebs", 
        "ami-04dae3806d64816cb"
    ], 
    [
        "2021-07-27T06:22:56.000Z", 
        "amzn2-ami-kernel-5.10-hvm-2.0.20210721.2-x86_64-gp2", 
        "ami-0a400300cff0c4af7"
    ], 
    [
        "2021-08-25T07:05:12.000Z", 
        "amzn2-ami-kernel-5.10-hvm-2.0.20210813.1-x86_64-ebs", 
        "ami-0eecf28412138ed1f"
    ], 
    [
        "2021-08-25T07:09:22.000Z", 
        "amzn2-ami-kernel-5.10-hvm-2.0.20210813.1-x86_64-gp2", 
        "ami-04a34e118b6354071"
    ], 
    [
        "2021-10-05T18:26:27.000Z", 
        "amzn2-ami-kernel-5.10-hvm-2.0.20211001.1-x86_64-ebs", 
        "ami-0829b69610d7b53b6"
    ], 
    [
        "2021-10-05T18:33:06.000Z", 
        "amzn2-ami-kernel-5.10-hvm-2.0.20211001.1-x86_64-gp2", 
        "ami-0331cc1e9ee0e02f5"
    ]
]

https://docs.aws.amazon.com/ko_kr/AWSEC2/latest/UserGuide/finding-an-ami.html

https://docs.aws.amazon.com/zh_tw/cli/latest/reference/ec2/describe-images.html

버지니아(us-east-1) Amazon Linux 2 AMI (HVM), SSD Volume Type 이미지

aws ec2 describe-images --region us-east-1 --image-id ami-02e136e904f3da870
$ aws ec2 describe-images --region us-east-1 --image-id ami-02e136e904f3da870
{
    "Images": [
        {
            "VirtualizationType": "hvm", 
            "Description": "Amazon Linux 2 AMI 2.0.20211001.1 x86_64 HVM gp2", 
            "PlatformDetails": "Linux/UNIX", 
            "EnaSupport": true, 
            "Hypervisor": "xen", 
            "ImageOwnerAlias": "amazon", 
            "State": "available", 
            "SriovNetSupport": "simple", 
            "ImageId": "ami-02e136e904f3da870", 
            "UsageOperation": "RunInstances", 
            "BlockDeviceMappings": [
                {
                    "DeviceName": "/dev/xvda", 
                    "Ebs": {
                        "SnapshotId": "snap-0a4c045433cade1b2", 
                        "DeleteOnTermination": true, 
                        "VolumeType": "gp2", 
                        "VolumeSize": 8, 
                        "Encrypted": false
                    }
                }
            ], 
            "Architecture": "x86_64", 
            "ImageLocation": "amazon/amzn2-ami-hvm-2.0.20211001.1-x86_64-gp2", 
            "RootDeviceType": "ebs", 
            "OwnerId": "137112412989", 
            "RootDeviceName": "/dev/xvda", 
            "CreationDate": "2021-10-05T18:18:39.000Z", 
            "Public": true, 
            "ImageType": "machine", 
            "Name": "amzn2-ami-hvm-2.0.20211001.1-x86_64-gp2"
        }
    ]
}
aws ec2 describe-images --region us-east-1 --image-id ami-02e136e904f3da870 \
--query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]"
$ aws ec2 describe-images --region us-east-1 --image-id ami-02e136e904f3da870 \
--query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]"
[
    [
        "2021-10-05T18:18:39.000Z", 
        "amzn2-ami-hvm-2.0.20211001.1-x86_64-gp2", 
        "ami-02e136e904f3da870"
    ]
]
728x90

공식 계정(official accounts)

  • amazon : 137112412989
  • centos : 125523088429
  • ubuntu : 099720109477
  • debian9 : 379101102735
  • debian10 : 136693071363
  • debian11 : 136693071363
  • redhat : 309956199498

Amazon EC2 AMI

amzn2(137112412989)

aws ec2 --profile terraform --region ap-northeast-2 describe-images --owners self amazon --filters "Name=owner-id,Values=137112412989" "Name=name,Values=amzn2-ami-hvm-2.0.*-x86_64-*" "Name=virtualization-type,Values=hvm" "Name=architecture,Values=x86_64" "Name=root-device-type,Values=ebs" --query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]" --output table

ubuntu-18.04(bionic/099720109477)

aws --profile terraform ec2 describe-images --owners 099720109477 --filters "Name=owner-id,Values=099720109477" "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-bionic-18.04-amd64-server-*" "Name=virtualization-type,Values=hvm" "Name=architecture,Values=x86_64" "Name=root-device-type,Values=ebs" --query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]" --output table

ubuntu-20.04(focal/099720109477)

aws --profile terraform ec2 describe-images --owners 099720109477 --filters "Name=owner-id,Values=099720109477" "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*" "Name=virtualization-type,Values=hvm" "Name=architecture,Values=x86_64" "Name=root-device-type,Values=ebs" --query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]" --output table

ubuntu-22.04(jammy/099720109477)

aws --profile terraform ec2 describe-images --owners 099720109477 --filters "Name=owner-id,Values=099720109477" "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-*" "Name=virtualization-type,Values=hvm" "Name=architecture,Values=x86_64" "Name=root-device-type,Values=ebs" --query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]" --output table

CentOS(125523088429)

aws --profile terraform ec2 describe-images --owners 125523088429 --filters "Name=owner-id,Values=125523088429" "Name=name,Values=CentOS*" "Name=virtualization-type,Values=hvm" "Name=architecture,Values=x86_64" "Name=root-device-type,Values=ebs" --query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]" --output table

Fedora-Cloud(125523088429)

aws --profile terraform ec2 describe-images --owners 125523088429 --filters "Name=owner-id,Values=125523088429" "Name=name,Values=Fedora-Cloud-Base-*-hvm-*" "Name=virtualization-type,Values=hvm" "Name=architecture,Values=x86_64" "Name=root-device-type,Values=ebs" --query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]" --output table

RHEL(309956199498)

aws --profile terraform ec2 describe-images --owners 309956199498 --filters "Name=owner-id,Values=309956199498" "Name=name,Values=RHEL-*_HVM_*-x86_64-*-GP2" "Name=virtualization-type,Values=hvm" "Name=architecture,Values=x86_64" "Name=root-device-type,Values=ebs" --query "sort_by(Images, &CreationDate)[*].[CreationDate,Name,ImageId]" --output table

 

참고URL

- https://sangchul.kr/401

- https://wiki.centos.org/Cloud/AWS

- https://cloud-images.ubuntu.com/locator/ec2/

- https://access.redhat.com/solutions/15356

 

728x90