They could have dropped the bomb on an uninhabited area, as a demonstration to the Japanese government. They could have allowed a longer period of time for the Japanese to surrender after Hiroshima instead of following up so quickly with the Nagasaki bomb. Etc. etc.
Overall, I agree with your point, better two cities lost than all the deaths that would have followed an invasion, but that's not to say that nuking two major cities was the best possible outcome