It's doable, but your yields will not be as high as if you grew in a cooler space. I've done this successfully though, so here's some tips off the top of my head:

1. Only grow during the cooler part of the year. You can try growing during the summer, but it'll be harder.
2. Have your lights come on at night. You don't need both the sun and your lights heating your attic.
3. Get heat-resistant strains. Mandala Seeds has some good ones.
4. Give your plants more dirt than they need. Letting them develop large root systems can mitigate heat stress.
5. Keep your plants watered. Plants are like people in that they can keep cool by drinking a lot. But if they run out of water, they're screwed.
6. Insulate your attic roof.
7. If you're replacing the roof any time soon, go for lighter-colored shingles.

Good luck!