apache - AWS PHP SDK Credentials error S -


i following error when trying create snsclient object.

instanceprofilecredentialsexception in instancemetadataclient.php line 85: error retrieving credentials instance profile metadata server. when not running inside of amazon ec2, must provide aws access key id , secret access key in "key" , "secret" options when creating client or provide instantiated aws\common\credentials\credentialsinterface object. (client error response [status code] 404 [reason phrase] not found [url] http://169.254.169.254/latest/meta-data/iam/security-credentials/) 

i don't understand why have error when have aws.php in config folder of laravel setup. here access key , secret key stored.

i don't since causes credentials stored in folder setup other's may sftp into.

what have aws credentials , config files in server root folder, in path this: ~/.aws/ reason application not happy.

here's code looks like:

public function about(){      // instantiate client credentials project1 profile     $snsclient = snsclient::factory(array(             'profile' => 'default',             'region'  => 'us-west-2',         ));      // application's endpoints      $ios_apparn = "arn:aws:sns:us-west-2:235418406768:app/apns_sandbox/clashtarget";      $ios_model = $snsclient->listendpointsbyplatformapplication(array('platformapplicationarn' => $ios_apparn)); } 

note using default profile should take credentials root aws directory config , credential files stored.

for now, temporary solution did this: http://blog.ianholden.com/aws-s3-with-php-on-apache/ makes work i'm not happy having credential keys living in application code. doesn't feel right.

can guide me in getting error resolved please?

update 1: comment: content of config @ ~/.aws/ content of config file in ~/.aws/ folder

[default] output = json region = us-west-2 

your ~/.aws/credentials file should this:

[default] aws_access_key_id = your_aws_access_key_id aws_secret_access_key = your_aws_secret_access_key  [project1] aws_access_key_id = another_aws_access_key_id aws_secret_access_key = another_aws_secret_access_key 

the following function used library determine directory in .aws/credentials file:

private static function gethomedir() {     // on linux/unix-like systems, use home environment variable     if ($homedir = getenv('home')) {         return $homedir;     }     // homedrive , homepath values windows hosts     $homedrive = getenv('homedrive');     $homepath = getenv('homepath');     return ($homedrive && $homepath) ? $homedrive . $homepath : null; } 

as can see, if home or homedrive , homepath environment variables not set, library not able find credentials file.

in addition being able find file, needs readable php, , in ini format (as described above).

edit

from comments, sounds home environment variable not set. because of this, library cannot find credentials file. there few options go here.

option 1:

fix server home environment variable set correctly. need research on best way this, solution may highly dependent on server/apache/php configurations...

option 2:

since you're using laravel 5, can add credentials .env file, , access them in code. so, example, add following 2 lines end of .env file:

aws_access_key_id=your_aws_access_key_id aws_secret_access_key=your_aws_secret_access_key 

now, in code, can do:

public function about() {     // add "use aws\credentials\credentials;" @ top of file      // env() method reads values .env file     $credentials = new credentials(env('aws_access_key_id'), env('aws_secret_access_key'));      // if using 'credentials' key, not use 'profile' key     $snsclient = snsclient::factory(array(         'region'  => 'us-west-2',         'credentials' => $credentials     )); } 

option 3:

call credentialprovider::ini() method , pass in profile , full path ini file. bypass need library try , determine home directory.

public function about() {     // add "use aws\credentials\credentialprovider;" @ top of file      // first parameter profile, second parameter full path credentials file     $credentials = credentialprovider::ini('default', '/root/.aws/credentials');      // if using 'credentials' key, not use 'profile' key     $snsclient = snsclient::factory(array(         'region'  => 'us-west-2',         'credentials' => $credentials     )); } 

Comments

Popular posts from this blog

javascript - Bootstrap Popover: iOS Safari strange behaviour -

Magento/PHP - Get phones on all members in a customer group -

session - Logging Out Using PHP -