When God wasn't contempt after creating the universe, he wanted that beauty should be recognized. Thus, he created lightning. According to Genesis 1:3, God had created light through his command. He simply commanded, "Let there be light" then light started to emit around.
Since light has a relationship to the Sun, I think that when God commanded "Let there be light", he created the Sun.