別質問で Fuel 上に環境変数を読み込む方法はわかったので
おそらく AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY を指定すれば動く気はするのですが、できればキーをかかずに .aws/config にかかれてある STS profile 情報で動作するようにしたいです

環境変数 AWS_PROFILE=staging

apache の起動ユーザの /home/.aws/config をかいても

Error retrieving credentials from the instance profile metadata server. When you are not running inside of Amazon EC2, you must provide your AWS access key ID and secret access key in the "key" and "secret" options when creating a client or provide an instantiated Aws\Common\Credentials\CredentialsInterface object.

というエラーになって S3 に書き込むことができません

$s3 = S3Client::factory();
$s3->putObject(array(
                'Bucket' => Config::get('aws.bucket'),
                'Key' => $s3BucketKey,
                'Body' => $compressed_posted_data,
                'ACL' => 'private',
                'ContentType' => 'application/json',
                'ContentEncoding' => 'gzip',
            ));

のような感じで書き込もうとしていて EC2上ではEC2 Roleを使って動いています

.aws/config, credentials のなかはみせるわけにいかないんですが
AWS_PROFILE=staging aws s3 ls のような aws cli はちゃんと指定したプロファイルで動作してます

https://docs.aws.amazon.com/aws-sdk-php/v2/guide/credentials.html#environment-credentials

If no credentials or profiles were explicitly provided to the SDK and no credentials were defined in environment variables, but a credentials file is defined, the SDK will use the "default" profile. You can change the default profile by specifying an alternate profile name in the AWS_PROFILE environment variable.

とあるので AWS_PROFILE さえ設定すれば動く気がするのですが何が問題なのでしょうか

原因をデバッグする方法はないでしょうか

追記

環境変数に HOME を定義することで $HOME/.aws/config をみにいってくれるようにはなりました

ERROR - 2019-09-11 07:44:14 --> Warning - syntax error, unexpected '=' in /home/apache/.aws/credentials on line 8
 in /home/git/api/fuel/vendor/aws/aws-sdk-php/src/Aws/Common/Credentials/Credentials.php on line 152

今度はこういうエラーが出てしまって
STS が自動付加している
aws_security_token = .......=
という security token の最後についてる = がパースエラーみたいです

(使うのは access_key と secret だけのはずなのに…)

これはさすがに STS が自動付与する設定に aws-sdk-php が対応してないのが原因みたいなので
どうしようもない気がしますが回避する方法はあるでしょうか…