기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.
AWS SDK for PHP 버전 3을 사용하여 Amazon EC2 인스턴스 관리
다음 예제에서는 다음과 같은 작업을 하는 방법을 보여줍니다.
-
를 사용하여 Amazon EC2 인스턴스를 설명하십시오. DescribeInstances
-
를 사용하여 MonitorInstances실행 중인 인스턴스에 대한 세부 모니터링을 활성화합니다.
-
를 사용하여 실행 중인 인스턴스에 대한 모니터링을 UnmonitorInstances비활성화합니다.
-
이전에 사용을 중단했던 Amazon EBS 기반 AMI를 시작하십시오. StartInstances
-
Amazon EBS 기반 인스턴스의 사용을 중지합니다. StopInstances
-
를 사용하여 하나 이상의 인스턴스 재부팅을 요청합니다. RebootInstances
의 모든 예제 코드는 여기에서 확인할
보안 인증 정보
예제 코드를 실행하기 전에 보안 인증 정보에 설명된 대로 AWS 보안 인증을 구성합니다. 그 다음 기본 사용법에 설명된 대로 AWS SDK for PHP를 가져옵니다.
인스턴스 설명
가져오기
require 'vendor/autoload.php'; use Aws\Ec2\Ec2Client;
샘플 코드
$ec2Client = new Aws\Ec2\Ec2Client([ 'region' => 'us-west-2', 'version' => '2016-11-15', 'profile' => 'default' ]); $result = $ec2Client->describeInstances(); echo "Instances: \n"; foreach ($result['Reservations'] as $reservation) { foreach ($reservation['Instances'] as $instance) { echo "InstanceId: {$instance['InstanceId']} - {$instance['State']['Name']} \n"; } }
모니터링 활성화 및 비활성화
가져오기
require 'vendor/autoload.php';
샘플 코드
$ec2Client = new Aws\Ec2\Ec2Client([ 'region' => 'us-west-2', 'version' => '2016-11-15', 'profile' => 'default' ]); $instanceIds = ['InstanceID1', 'InstanceID2']; $monitorInstance = 'ON'; if ($monitorInstance == 'ON') { $result = $ec2Client->monitorInstances([ 'InstanceIds' => $instanceIds ]); } else { $result = $ec2Client->unmonitorInstances([ 'InstanceIds' => $instanceIds ]); } var_dump($result);
인스턴스 시작 및 중지
가져오기
require 'vendor/autoload.php';
샘플 코드
$ec2Client = new Aws\Ec2\Ec2Client([ 'region' => 'us-west-2', 'version' => '2016-11-15', 'profile' => 'default' ]); $action = 'START'; $instanceIds = ['InstanceID1', 'InstanceID2']; if ($action == 'START') { $result = $ec2Client->startInstances([ 'InstanceIds' => $instanceIds, ]); } else { $result = $ec2Client->stopInstances([ 'InstanceIds' => $instanceIds, ]); } var_dump($result);
인스턴스 재부팅
가져오기
require 'vendor/autoload.php';
샘플 코드
$ec2Client = new Aws\Ec2\Ec2Client([ 'region' => 'us-west-2', 'version' => '2016-11-15', 'profile' => 'default' ]); $instanceIds = ['InstanceID1', 'InstanceID2']; $result = $ec2Client->rebootInstances([ 'InstanceIds' => $instanceIds ]); var_dump($result);