以下の内容はhttps://kakakakakku.hatenablog.com/entry/2025/06/16/102002より取得しました。


MOTO_AMIS_PATH: Moto に独自の AMI を登録する

Moto に登録されている AMI (Amazon Machine Image) 情報は実際に AWS から取得された値になっていて,頻度高く(毎月)更新されている👌たとえば Moto の us-east-1 リージョンや ap-northeast-1 リージョンで AMI を検索すると Amazon Linux 2023 AMI 2023.7.20250512.0 x86_64 HVM kernel-6.1 が登録されている.

$ docker run --rm -p 5000:5000 --name moto motoserver/moto

# バージニア北部 (us-east-1) リージョン
$ aws ec2 describe-images --endpoint-url http://localhost:5000 \
  --filters "Name=name,Values=al2023-ami-2023.7.20250512.0-kernel-6.1-x86_64" \
  --region us-east-1
{
    "Images": [
        {
            "BlockDeviceMappings": [
                {
                    "Ebs": {
                        "DeleteOnTermination": false,
                        "SnapshotId": "snap-80a08054675345fb6",
                        "VolumeSize": 15,
                        "VolumeType": "standard"
                    },
                    "DeviceName": "/dev/xvda"
                }
            ],
            "Description": "Amazon Linux 2023 AMI 2023.7.20250512.0 x86_64 HVM kernel-6.1",
            "Hypervisor": "xen",
            "ImageOwnerAlias": "amazon",
            "Name": "al2023-ami-2023.7.20250512.0-kernel-6.1-x86_64",
            "RootDeviceName": "/dev/xvda",
            "RootDeviceType": "ebs",
            "Tags": [],
            "VirtualizationType": "hvm",
            "ImageId": "ami-0953476d60561c955",
            "ImageLocation": "None",
            "State": "available",
            "OwnerId": "137112412989",
            "CreationDate": "2025-06-10T14:57:29.000Z",
            "Public": true,
            "Architecture": "x86_64",
            "ImageType": "machine",
            "KernelId": "None",
            "RamdiskId": "ari-1a2b3c4d"
        }
    ]
}

# 東京 (ap-northeast-1) リージョン
$ aws ec2 describe-images --endpoint-url http://localhost:5000 \
  --filters "Name=name,Values=al2023-ami-2023.7.20250512.0-kernel-6.1-x86_64" \
  --region ap-northeast-1
{
    "Images": [
        {
            "BlockDeviceMappings": [
                {
                    "Ebs": {
                        "DeleteOnTermination": false,
                        "SnapshotId": "snap-ce820459498b5678a",
                        "VolumeSize": 15,
                        "VolumeType": "standard"
                    },
                    "DeviceName": "/dev/xvda"
                }
            ],
            "Description": "Amazon Linux 2023 AMI 2023.7.20250512.0 x86_64 HVM kernel-6.1",
            "Hypervisor": "xen",
            "ImageOwnerAlias": "amazon",
            "Name": "al2023-ami-2023.7.20250512.0-kernel-6.1-x86_64",
            "RootDeviceName": "/dev/xvda",
            "RootDeviceType": "ebs",
            "Tags": [],
            "VirtualizationType": "hvm",
            "ImageId": "ami-0c1638aa346a43fe8",
            "ImageLocation": "None",
            "State": "available",
            "OwnerId": "137112412989",
            "CreationDate": "2025-06-10T14:57:29.000Z",
            "Public": true,
            "Architecture": "x86_64",
            "ImageType": "machine",
            "KernelId": "None",
            "RamdiskId": "ari-1a2b3c4d"
        }
    ]
}

仕組みとしては GitHub Actions ワークフロー .github/workflows/data-update_ssm-default-amis.ymlscripts/ssm_get_default_amis.py を実行して,最終的にリージョンごとに Amazon Linux 関連の AMI 情報を moto/ec2/resources/latest_amis/*.json に保存している感じ〜❗️

github.com

独自の AMI を登録する

さらに Moto には独自の AMI を登録する仕組みもあって,環境変数 MOTO_AMIS_PATH に JSON ファイルを指定すると自動的にロードされるようになっている👌テストで使うダミーデータとして登録できたりする.

If you require specific AMIs to be available during your tests, you can provide your own AMI definitions by setting the environment variable MOTO_AMIS_PATH to point to a JSON file containing definitions of the required AMIs. No other AMI’s will be loaded if this environment variable is set.

docs.getmoto.org

👾 amis.json

サンプルとして Sample-AMI-2025-06 (ami-99999999999999999) という AMI 情報を ~/amis.json に設定しておく.

[
  {
    "ami_id": "ami-99999999999999999",
    "state": "available",
    "public": true,
    "owner_id": "999999999999",
    "image_location": "None",
    "sriov": "simple",
    "root_device_type": "ebs",
    "root_device_name": "/dev/sda1",
    "description": "Sample-AMI-2025-06",
    "image_type": "machine",
    "platform": "windows",
    "architecture": "x86_64",
    "name": "Sample-AMI-2025-06",
    "virtualization_type": "hvm",
    "hypervisor": "xen"
  }
]

そして,以下のように環境変数 MOTO_AMIS_PATH~/amis.json を指定して Moto (Server Mode) を起動する.

$ docker run --rm -p 5000:5000 \
  --name moto \
  -v ~/amis.json:/moto/amis.json \
  -e MOTO_AMIS_PATH=/moto/amis.json \
  motoserver/moto

すると ~/amis.json が優先的にロードされるため,以下のように Sample-AMI-2025-06 を取得できるようになる❗️

# バージニア北部 (us-east-1) リージョン
$ aws ec2 describe-images --endpoint-url http://localhost:5000 \
  --region us-east-1
{
    "Images": [
        {
            "BlockDeviceMappings": [
                {
                    "Ebs": {
                        "DeleteOnTermination": false,
                        "SnapshotId": "snap-4cfec037fcda8435e",
                        "VolumeSize": 15,
                        "VolumeType": "standard"
                    },
                    "DeviceName": "/dev/sda1"
                }
            ],
            "Description": "Sample-AMI-2025-06",
            "Hypervisor": "xen",
            "ImageOwnerAlias": "amazon",
            "Name": "Sample-AMI-2025-06",
            "RootDeviceName": "/dev/sda1",
            "RootDeviceType": "ebs",
            "Tags": [],
            "VirtualizationType": "hvm",
            "ImageId": "ami-99999999999999999",
            "ImageLocation": "None",
            "State": "available",
            "OwnerId": "999999999999",
            "CreationDate": "2025-06-12T16:01:29.000Z",
            "Public": true,
            "Architecture": "x86_64",
            "ImageType": "machine",
            "KernelId": "None",
            "RamdiskId": "ari-1a2b3c4d",
            "Platform": "windows"
        }
    ]
}

# 東京 (ap-northeast-1) リージョン
$ aws ec2 describe-images --endpoint-url http://localhost:5000 \
  --region ap-northeast-1
{
    "Images": [
        {
            "BlockDeviceMappings": [
                {
                    "Ebs": {
                        "DeleteOnTermination": false,
                        "SnapshotId": "snap-8eb68c280c406e39a",
                        "VolumeSize": 15,
                        "VolumeType": "standard"
                    },
                    "DeviceName": "/dev/sda1"
                }
            ],
            "Description": "Sample-AMI-2025-06",
            "Hypervisor": "xen",
            "ImageOwnerAlias": "amazon",
            "Name": "Sample-AMI-2025-06",
            "RootDeviceName": "/dev/sda1",
            "RootDeviceType": "ebs",
            "Tags": [],
            "VirtualizationType": "hvm",
            "ImageId": "ami-99999999999999999",
            "ImageLocation": "None",
            "State": "available",
            "OwnerId": "999999999999",
            "CreationDate": "2025-06-12T16:02:17.000Z",
            "Public": true,
            "Architecture": "x86_64",
            "ImageType": "machine",
            "KernelId": "None",
            "RamdiskId": "ari-1a2b3c4d",
            "Platform": "windows"
        }
    ]
}

関連記事

kakakakakku.hatenablog.com

kakakakakku.hatenablog.com




以上の内容はhttps://kakakakakku.hatenablog.com/entry/2025/06/16/102002より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14