"Little tyke wants his money's worth, just like his father. 'Atta boy, Dudley!" He ruffled Dudley's hair. (Harry Potter and the Sorcerer's Stone)
Why is the apostrophe put before Atta boy?
‘Atta boy is short for That’s a good boy or, as M-W online says, “attaboy: probably alteration of that’s the boy”.
Because it's a shortened form, the apostrophe replaces the two missing letters of “that”, just as it replaces the initial “i” in “‘Twas” (“It was”).