Created
August 31, 2018 08:40
-
-
Save ZerglingGo/55c6d99335cd06b48df6326d9e5240a7 to your computer and use it in GitHub Desktop.
PHP AWS Elastic IP Allocator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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