Debian publishes their releases of Amazon Machine Image (AMI) for bookworm at Debian bookworm on Amazon EC2 [1]. There, you can find the AMIs for various regions and two architecture amd64 and arm64.

Another way to search for AMI for Debian 12 (bookworm) is to use AWS CLI with describe-images. Here is an example on how to list the 3 most recent AMIs of Debian 12 (amd64 architecture), sorted by most recent to the oldest:

❯ aws ec2 describe-images --owner amazon --filters "Name=name,Values=debian-12*" \
--query 'reverse(sort_by(Images, &CreationDate))[:3].{ImageId:ImageId,CreationDate:CreationDate}'
[
    {
        "ImageId": "ami-08ac0fc0cba8deca9",
        "CreationDate": "2023-08-02T13:57:32.000Z"
    },
    {
        "ImageId": "ami-0990d30531b9123cb",
        "CreationDate": "2023-08-02T13:52:37.000Z"
    },
    {
        "ImageId": "ami-0ef2a8b923aaa00b7",
        "CreationDate": "2023-07-24T09:12:12.000Z"
    }
]

And to get only the latest AMI, we can tune in the CLI a bit more as the following:

❯ aws ec2 describe-images --owner amazon --filters "Name=name,Values=debian-12*" \
--query 'reverse(sort_by(Images, &CreationDate))[0].ImageId' --output text
ami-08ac0fc0cba8deca9

But, is there another way to do the same thing? Maybe something a bit more elegant you ask? Yes, there is and you know this ‘cuz this post title must have given a way the obvious clue.

The third way is to use AWS Systems Manager (SSM) Parameter Store. I did know that for Amazon Linux AMI, there is a public SSM parameter store which we can use, but I did not know Debian AMI also has similar public parameter store.

To list the latest Debian 12 (bookworm) AMI, run the following AWS CLI command:

❯ aws ssm get-parameters-by-path --path /aws/service/debian/release/bookworm/latest
{
    "Parameters": [
        {
            "Name": "/aws/service/debian/release/bookworm/latest/amd64",
            "Type": "String",
            "Value": "ami-08ac0fc0cba8deca9",
            "Version": 5,
            "LastModifiedDate": "2023-08-03T00:08:16.495000+10:00",
            "ARN": "arn:aws:ssm:ap-southeast-2::parameter/aws/service/debian/release/bookworm/latest/amd64",
            "DataType": "text"
        },
        {
            "Name": "/aws/service/debian/release/bookworm/latest/arm64",
            "Type": "String",
            "Value": "ami-0990d30531b9123cb",
            "Version": 5,
            "LastModifiedDate": "2023-08-03T00:08:54.216000+10:00",
            "ARN": "arn:aws:ssm:ap-southeast-2::parameter/aws/service/debian/release/bookworm/latest/arm64",
            "DataType": "text"
        }
    ]
}

And, to get just the AMI ID for amd64 architecture, here is one way to do that:

❯ aws ssm get-parameters --name /aws/service/debian/release/bookworm/latest/amd64 \
--query 'Parameters[].Value' --output text
ami-08ac0fc0cba8deca9

Voilla, the outputs for the latest Debian 12 AMI (amd64) are both the same. However, in my opinion, using querying the AMI with SSM Parameter Store is much faster.

References: