1

Hi I am using aws SDK Version 3 for php to upload files on s3 I need to get rid of credentials file ( .aws/credentials) because it's causing issues on my production server,

The hard coded credentials method isn't working in my code. link pasted below.

https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html#hardcoded-credentials

kindly provide a valid and working solution how to use hard coded credentials. please note if i use credential file everything works OK. so the problem is with credentials code.

here is my code when I initiate my s3 object

$s3Client = new S3Client([
                    'profile' => 'default',
                    'region' => 'us-west-2',
                    'version' => '2006-03-01',
                    'scheme'  => 'http',
                    'credentials'=>[
                        'key' => KEY,
                        'secret' => SECRET
                    ]
                ]);

3 Answers3

6

You just need to remove the 'profile' => 'default', line, which has the effect of overriding your hard-coded credentials.

I've been dealing with your same problem with much frustration today, and finally solved it. See related answer here for the same problem on a different Amazon service.

Daniel Von Fange
  • 857
  • 9
  • 10
0

per AWS documentation, https://docs.aws.amazon.com/aws-sdk-php/v2/guide/credentials.html

If you do not provide credentials to a client object at the time of its instantiation (e.g., via the client's factory method or via a service builder configuration), the SDK will attempt to find credentials in your environment when you call your first operation. The SDK will use the $_SERVER superglobal and/or getenv() function to look for the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables. These credentials are referred to as environment credentials.

sothish
  • 416
  • 3
  • 8
  • have you guys ever tried this documentation?? its not working at all.at least test the code first before putting your answers as guess here. – Azam Maqsood May 18 '18 at 11:40
0

V3 doc here https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html In my case I am using an IAM role in the machines which host the app, it is easier to manage permissions from IAM dashboard and you will avoid hardcoded or config file with credentials.

Conti
  • 1,153
  • 9
  • 12