amazon web services - Different output in AWS PHP SDK than in AWSCLI -
the primary goal i'm trying achieve iterate on running ec2 instances in php.
it's easy data using bash script, shown below:
bash script:
#!/bin/bash export aws_access_key_id="akidexample" export aws_secret_access_key="wjalrxutnfemi/k7mdeng+bpxrficyexamplekey" aws ec2 describe-instances --region="eu-west-1" --filter "name=instance-state-name,values=running"
bash output:
{ "reservations": [ { "ownerid": "58728357357", "reservationid": "r-0e0283649826935", "instances": [ { "securitygroups": [ { "groupid": "sg-2fe333148", "groupname": "web" } ], "publicdnsname": "ec2-53-13-121-72.eu-west-1.compute.amazonaws.com", "architecture": "x86_64", "launchtime": "2016-07-11t08:28:23.000z", "rootdevicename": "/dev/sda1", "blockdevicemappings": [ { "ebs": { // ... } ] }
however, when try following example, using same keys, presented seems unusable object - or @ least object looks representing empty data structure.
php file:
<?php require __dir__ . "/vendor/autoload.php"; $settings = [ "version" => "latest", "region" => "eu-west-1", "credentials" => [ "key" => "akidexample", "secret" => "wjalrxutnfemi/k7mdeng+bpxrficyexamplekey", ], ]; $client = new \aws\ec2\ec2client($settings); $result = $client->describeinstances([ "filters" => [ [ "name" => "instance-state-name", "value" => "running", ] ], ]); var_dump($result);
php output:
what hell meant aws\result?
class aws\result#82 (1) { private $data => array(2) { 'reservations' => array(0) { } '@metadata' => array(4) { 'statuscode' => int(200) 'effectiveuri' => string(35) "https://ec2.eu-west-1.amazonaws.com" 'headers' => array(5) { ... } 'transferstats' => array(1) { ... } } } }
am missing in php configuration? please can point me in right direction?
p.s. i've masked api keys in above examples.
ec2::describeinstances takes array of filters, each of has string name
, array of string values
. in cli example, you've supplied values
, whereas in php example you've supplied value
instead. field not recognized sdk , ignored. see the sdk api docs more information.
your php should updated read:
<?php require __dir__ . "/vendor/autoload.php"; $settings = [ "version" => "latest", "region" => "eu-west-1", "credentials" => [ "key" => "akidexample", "secret" => "wjalrxutnfemi/k7mdeng+bpxrficyexamplekey", ], ]; $client = new \aws\ec2\ec2client($settings); $result = $client->describeinstances([ "filters" => [ [ "name" => "instance-state-name", "values" => ["running"], ] ], ]); var_dump($result);
Comments
Post a Comment