IAM role with AWS SDK for php not working

I am trying to get detailed information on all EC2 instances running on AWS using the AWS SDK for PHP. To do this, I use an IAM role that I have already bound to another instance running the AWS SDK.

Here is my code:

require_once 'sdk.class.php';


$ec2 = new AmazonEC2(array(
  'default_cache_config' => '/tmp/secure-dir'
));

$result = $ec2->describe_instances();



$response = json_encode($result);

      

I created / tmp / secure -dir with full permissions. But when I execute the above script it returns "Auth Failure"

.

However, I can get information about all servers using AWS CLI.

Is there something I am missing?

Can anyone help me?

+3


source to share





All Articles