Use AMI IDs in sorting to make sorting stable