Since you report the sound diminishes when the camera is powered on, it is probably the image stabilizer. The S8 comes with an optical image stabilizer. Unlike an electronic image stabilizer which works in software by shifting recorded pixels, an OIS works by mounting a camera lens element(s) in a unit which is free to tilt and shift relative to the camera sensor. The movement of the OIS unit aims the light coming through the lens so it's focused on the same spot on the sensor regardless of how you shake the camera (up to a limit of course).
When the camera is unpowered, the OIS unit is free to move and can create a ratting sound as it shakes around. When the camera is powered, you'll still get some rattling any time the OIS unit...