Skip to content

Instantly share code, notes, and snippets.

@ZerglingGo
Created August 31, 2018 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ZerglingGo/55c6d99335cd06b48df6326d9e5240a7 to your computer and use it in GitHub Desktop.
Save ZerglingGo/55c6d99335cd06b48df6326d9e5240a7 to your computer and use it in GitHub Desktop.
PHP AWS Elastic IP Allocator
<?php
require 'vendor/autoload.php';
use Aws\Ec2\Ec2Client;
$ec2Client = new Ec2Client([
'region' => 'ap-northeast-2',
'version' => 'latest',
'profile' => 'default',
]);
while(true) {
$allocate = $ec2Client->allocateAddress();
echo "A new address has been created: ".$allocate['PublicIp'].PHP_EOL;
$result = readline("Save address? [Y/n/q/nq]: ");
if(strtolower($result) == "n" || strtolower($result) == "nq") {
$ec2Client->releaseAddress([
'AllocationId' => $allocate['AllocationId'],
]);
echo "Address removed".PHP_EOL;
if(strtolower($result) == "nq") {
break;
}
} elseif(strtolower($result) == "q") {
break;
} else {
echo "Address saved: ".$allocate['PublicIp'].PHP_EOL;
}
echo PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment