A lot depends on what you want to see and do. May-June less rain more animal sightings, better fishing for kings (if they open a season) more bugs and more tourists. August-September could be rainy could be dry and sunny, less animals, better fishing for silvers, better fall colors, less tourists, but possible snow and cold weather in the rockies. You might have to stay in one place for a couple of days while the snow melts.
We've been there for four summers from mid May to mid September and have enjoyed the entire time each year. This year was pretty wet in the summer but we managed to find things to do to keep us busy. An besides it hardly ever RAINS in Alaska. Usually it is a drizzle or something less than .25" a day.
Read the blogs, read the brochures, and check the historical weather reports and make your decision around what you want to see and do. No one can really say what would be best for you!