简体   繁体   中英

Where to save AWS Credentials file when using shared hosting?

I'm using Amazon's AWS PHP SDK and I installed composer on the following directory 'public_html/composer'. I am currently using shared hosting. However, I have access to the root.

When I tried using AWS's sample code I'm getting the following errors in my error_log:

Fatal error: Uncaught Aws\Exception\CredentialsException: Cannot read credentials from /.aws/credentials in /home2/maltaboo/public_html/composer/vendor/aws/aws-sdk-php/src/Credentials/CredentialProvider.php:691 Stack trace: #0 /home2/maltaboo/public_html/composer/vendor/aws/aws-sdk-php/src/Credentials/CredentialProvider.php(424): Aws\Credentials\CredentialProvider::reject('Cannot read cre...') #1 /home2/maltaboo/public_html/composer/vendor/aws/aws-sdk-php/src/Middleware.php(121): Aws\Credentials\CredentialProvider::Aws\Credentials\{closure}() #2 /home2/maltaboo/public_html/composer/vendor/aws/aws-sdk-php/src/RetryMiddleware.php(266): Aws\Middleware::Aws\{closure}(Object(Aws\Command), Object(GuzzleHttp\Psr7\Request)) #3 /home2/maltaboo/public_html/composer/vendor/aws/aws-sdk-php/src/Middleware.php(206): Aws\RetryMiddleware->__invoke(Object(Aws\Command), Object(GuzzleHttp\Psr7\Request)) #4 /home2/maltaboo/public_html/composer/vendor/aws/aws-sdk-php/src/StreamRequestPayloadMiddleware.php(83): Aws\Middleware::Aws\{closure}(Ob in /home2/maltaboo/public_html/composer/vendor/aws/aws-sdk-php/src/Credentials/CredentialProvider.php on line 691

I created my credentials files as per AWS tutorial:

[default]
aws_access_key_id = 123456789
aws_secret_access_key = abcdefghijklm

The documentation states that I must save it in this location: ~/.aws/credentials

I tried many times to create the directory .aws/credentials however I get the same error. I tried also looking for the .aws file but I couldn't locate it except the one that I just created.

Given the above where should I place the credentials file? TIA

I also had the same issue of cannot read /.aws/credentials

Mentioning my solution here for reference:

This solution is tested in aws-php-sdk version 3.173 :

CredentialProvider.php uses getenv('HOME')/.aws/credentials path to load the credentials from the file.

In my case (linux shared hosting) it was empty.

So I set it to desired value using:

putenv("HOME=/absolute/path/to/folder/containing/.aws/folder")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM