Amazon owns IMDb. They have been gathering data about actors for literally decades. They probably have well-trained machine learning models to identify actors on screen.
It's really not that hard since they can run it against a narrowed down dataset with the names of the cast.