aws ec2 の ami 検索方法

aws ec2 の ami 検索方法

2024/01/18 02:00:00
Program
Aws

前提 #

  • aws cli が使える環境

使い方 #

$ aws ec2 describe-images コマンドで ami 検索することが可能
オプションの意味は以下の通り

  • –region … リージョン名
  • –owners … amazon は amazonが開発元, 099720109477 は ubuntu開発元
  • –query … [-1]: 最古, [0]: 最新, [:10]: 最新10個
  • –output … 出力形式(text,json,yaml,yaml-stream,table…)
# リージョン:ap-northeast-1(東京)で利用可能な amazon linux 最新1個
$ aws ec2 describe-images --region ap-northeast-1 --owners amazon \
 --filters "Name=name,Values=amzn2-ami-hvm-2.0.*-x86_64-gp2" \
 --query "reverse(sort_by(Images, &CreationDate))[0].[ImageId,CreationDate,Name]" \
 --output text
ami-022c3cb73fbed1cc7   2024-01-09T23:41:01.000Z        amzn2-ami-hvm-2.0.20240109.0-x86_64-gp2

# リージョン:ap-northeast-1(東京)で利用可能な ubuntu20.04 最新10個
$ aws ec2 describe-images --region ap-northeast-1 --owners 099720109477 \
 --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64*" \
 --query "reverse(sort_by(Images, &CreationDate))[:10].[ImageId,CreationDate,Name]" \
 --output text
ami-07a48f4a2abe3a5fc   2023-12-08T23:21:12.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20231208
ami-0970b3a12761f4b74   2023-11-28T01:10:10.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20231127
ami-088d0210bf28bccd0   2023-11-21T23:23:52.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20231121.1
ami-0e87e519e7ca35ccd   2023-11-17T23:40:26.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20231117
ami-0c4f29be32be77ca3   2023-10-30T23:07:04.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20231030
ami-0f7b55661ecbbe44c   2023-10-26T04:00:03.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20231025
ami-09c4f01da470a73b5   2023-10-20T23:14:44.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20231020.1
ami-06b9669e2d3108be8   2023-10-05T00:06:52.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20231004
ami-0e25df74d27e028e6   2023-09-19T04:16:12.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20230918
ami-0a9ba7a24c49007d3   2023-09-07T00:24:25.000Z        ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-20230906

# リージョン:ap-northeast-1(東京)で利用可能な ubuntu22.04 最新10個
$ aws ec2 describe-images --region ap-northeast-1 --owners 099720109477 \
 --filters "Name=name,Values=ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64*" \
 --query "reverse(sort_by(Images, &CreationDate))[:10].[ImageId,CreationDate,Name]" \
 --output text
ami-09ad00fde226b2867   2024-01-18T02:45:58.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20240118
ami-07c589821f2b353aa   2023-12-07T03:26:14.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20231207
ami-0289dadfee5556302   2023-11-28T04:30:01.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20231128
ami-0dadff2c5c2f5f1b7   2023-11-21T02:51:12.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20231121
ami-0a90bf37d2fa7fd4c   2023-11-17T04:18:52.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20231117
ami-0495363ae63d1182e   2023-10-30T21:28:18.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20231030
ami-0640caada745d9cca   2023-10-25T06:15:06.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20231025
ami-066b74b421294f8ec   2023-10-21T04:13:41.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20231021
ami-09a81b370b76de6a2   2023-09-19T05:30:46.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20230919
ami-09937bb9852528c94   2023-09-07T04:27:28.000Z        ubuntu/images/hvm-ssd/ubuntu-jammy-22.04-amd64-server-20230907