irap/

ec2-wrapper

用于简化AWS EC2操作的包。

0.3.4 2023-07-17 13:02 UTC

README

此包封装了Amazon的SDK for EC2,以提供更面向对象的接口。因此,开发者将花费更少的时间查找可以传递到数组中的参数。此版本的包装器基于SDK的第三个版本

示例用法

<?php 

require_once(__DIR__ . '/vendor/autoload.php');

// create the ec2 client.
$ec2Client = new iRAP\Ec2Wrapper\Ec2Client(
    'myApiKey', 
    'myApiSecret', 
    \iRAP\Ec2Wrapper\Enums\AwsRegion::create_EU_W1()
);

$ubuntuImage = 'ami-cc166eb5';

$launchSpec = new \iRAP\Ec2Wrapper\Objects\LaunchSpecification(
    \iRAP\Ec2Wrapper\Enums\Ec2InstanceType::createT2($size=1),  // 1 = nano
    $ubuntuImage,
    "Name for my instance"
);

// launch 3 instances
$request = new iRAP\Ec2Wrapper\Requests\RequestRunInstances($launchSpec, 3, 3); 
$launchResponse = $ec2client->launchInstances($request);

// get info on the instances we launched.
$launchedInstances = $launchResponse->getEc2Instances();

// Get all of our running instances...
$response = $ec2client->describeInstances();
$instances = $response->getEc2Instances();

// ...and terminate them.
foreach ($instances as $instance)
{
    /* @var $instance \iRAP\Ec2Wrapper\Objects\Ec2Instance */
    $instance->terminate($ec2client);
}