And they shall serve as lights in the firmament. This teaches that they were created only for the sake of humanity who are on the earth, as it is says, to shine upon the earth. (Genesis 1:17) But the Holy Blessed Infinite God does not need light, as there is light with him, as it says, and light dwells with him. (Daniel 2:22)
Why God Hung the Sun and Moon Only for Human Eyes
Midrash Aggadah, Genesis 1:15