How to store S3 credentials in environment variables? For a Craft 2 S3 asset source, access keys are expected to be entered in from the Control Panel. Is there a way to supply the access key and secret through environment variables instead?
Not really.

In Craft 2 S3 settings ultimately get stored in the database.

Normally the answer would be "you can write a plugin that adds its own Asset Source Type and changes that behavior", but in Craft 2, it is not easy to add custom Asset Source Types, either.

Craft 3 has solved both of those problems.  You can register custom Asset Volume Types as well as override Volume settings.