install AWS CLI first
yum install php-xml
in apache httpd.conf: setenv HOME /usr/share/httpd
After checking selinux log /var/log/audit/audit.log I could see this was denied by selinux:
tune selinux or simply disable: setenforce 0; sestatus
https://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.Ec2.Ec2Client.html
https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_jmespath.html
https://github.com/awsdocs/aws-doc-sdk-examples/tree/master/php/example_code
https://www.php.net/manual/en/function.var-dump.php
https://learnxinyminutes.com/docs/php
http://phpfiddle.org/lite
http://ideone.com/
php -a
http://phpfiddle.org/lite
http://ideone.com/
php -a
<?php require 'vendor/autoload.php'; use Aws\Ec2\Ec2Client; $ec2Client = new Aws\Ec2\Ec2Client([ 'region' => 'us-west-2', 'version' => '2016-11-15', 'profile' => 'default' // profile under .aws on apache home directory ]); $result = $ec2Client->describeInstances(); var_dump($result);
<?php require 'vendor/autoload.php'; use Aws\Ec2\Ec2Client; $ec2Client = new Aws\Ec2\Ec2Client([ 'region' => 'us-west-2', 'version' => '2016-11-15', 'profile' => 'default' ]); $action = 'START'; $instanceIds = array('InstanceID1', 'InstanceID2'); if ($action == 'START') { $result = $ec2Client->startInstances(array( 'InstanceIds' => $instanceIds, )); } else { $result = $ec2Client->stopInstances(array( 'InstanceIds' => $instanceIds, )); } var_dump($result);
No comments:
Post a Comment