Amazon EC2, or Amazon Elastic Compute Cloud, is one of the core services of Amazon Web Services. It is an elastic public cloud, where AWS EC2 instances, are VPS-type virtual servers.
The AWS EC2-compatible API provides limited compatibility of the methods provided to manage virtual resources such as virtual machines, virtual disks, private networks. Each location has its own API endpoint:
https://eu-poland-1poznan.api.e24cloud.com
https://eu-poland-1poznan2.api.e24cloud.com
Przykładowy kod PHP, korzystający z API zgodnym z EC2 z użyciem AWS-SDK for PHP.
$client = new \Aws\Ec2\Ec2Client([
'version' => '2015-04-15',
"credentials" => [
"key" => " api key",
"secret" => " api secret ",
],
'region' => 'eu-poland-1poznan',
'endpoint_provider' => function (array $params) {
return ['endpoint' => 'https://'.$params['region'].'.api.e24cloud.com'];
},
'signature_provider' => function ($version, $service, $region) {
return new \Aws\Signature\SignatureV2();
},
]);
$result = $client->describeImages();
foreach($result['Images'] as $image) {
echo "ImageId: ".$image['ImageId'].', Name: '.$image['Name'], PHP_EOL;
}
$result = $client->runInstances(array(
'ImageId' => 'ami-000006d8', // ImageId z describeImages
'MinCount' => 1,
'MaxCount' => 1,
'InstanceType' => 'm1.xlarge',
));
$result = $client->describeInstances();
foreach($result['Reservations'] as $reservation) {
foreach($reservation['Instances'] as $instance) {
echo 'id: '.$instance['InstanceId'].', type: '.$instance['InstanceType'].', State: '.$instance['State']['Name'].', PublicIp: '.$instance['PublicIpAddress'], PHP_EOL;
}
}
$client->stopInstances(array(
'InstanceIds' => array('70b9e613-d01a-4581-b29f-ba4b6fcebae9')
));
$client->startInstances(array(
'InstanceIds' => array('70b9e613-d01a-4581-b29f-ba4b6fcebae9')
));
$client->terminateInstances(array(
'InstanceIds' => array('70b9e613-d01a-4581-b29f-ba4b6fcebae9')
));
Since not all services available in e24cloud have their counterparts in the EC2 API call convention, not all calls are available. The following calls are available: