The origin of the idiom is somewhat unclear, but it is believed to stem from a popular 19th-century American song called "The Life of Riley." This song, often sung in vaudeville shows, depicted a character named Riley who lived a seemingly idyllic life, free from responsibility and work.
Over time, the phrase "living the life of Riley" became synonymous with a comfortable and carefree lifestyle. It's often used humorously to describe someone who seems to be enjoying themselves while others are struggling.