How to use AWS PHP SDK v3.0, without credential file

by Azam Maqsood   Last Updated August 14, 2019 18:26 PM

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.

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',
                        'key' => KEY,
                        'secret' => SECRET

Answers 3

per AWS documentation,

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.

May 17, 2018 15:29 PM

V3 doc here 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.

May 18, 2018 08:24 AM

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
Daniel Von Fange
August 14, 2019 18:26 PM

Related Questions

Dependency based ETL flow in AWS

Updated September 11, 2017 23:26 PM

AWS Glue Crawlers and large tables stored in S3

Updated October 30, 2018 15:26 PM