Ecclesiastes 1:1 (ESV)

1 The words of the Preacher, the son of David, king in Jerusalem.

We see Solomon, the king of Israel as the author of this book. At the end of Solomon's life, he realised the vanity of many of the decisions of his life and wrote this book about it.