2019-01-28 16:49:11 -08:00
< ? php
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
2024-02-05 10:49:20 -07:00
2019-01-28 16:49:11 -08:00
/*
* ABOUT THIS PHP SAMPLE => This sample is part of the SDK for PHP Developer Guide topic at
*
*
*/
// snippet-start:[lightsail.php.get_instance_state.complete]
// snippet-start:[lightsail.php.get_instance_state.import]
require 'vendor/autoload.php' ;
2024-02-05 10:49:20 -07:00
2019-01-28 16:49:11 -08:00
use Aws\Exception\AwsException ;
2024-02-05 10:49:20 -07:00
2019-01-28 16:49:11 -08:00
// snippet-end:[lightsail.php.get_instance_state.import]
2024-02-05 10:49:20 -07:00
2019-01-28 16:49:11 -08:00
/**
* Get the state of a single Amazon Lightsail Instance.
*
* This code expects that you have AWS credentials set up per:
* https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
*/
2024-02-05 10:49:20 -07:00
2019-01-28 16:49:11 -08:00
//Create a Lightsail Client
// snippet-start:[lightsail.php.get_instance_state.main]
$client = new Aws\Lightsail\LightsailClient ([
'profile' => 'default' ,
'version' => '2016-11-28' ,
'region' => 'us-east-2'
]);
2024-02-05 10:49:20 -07:00
2019-01-28 16:49:11 -08:00
$instanceName = 'AWS_SDK_PHP-Amazon_Linux' ;
2024-02-05 10:49:20 -07:00
2019-01-28 16:49:11 -08:00
try {
$result = $client -> getInstanceState ([
'instanceName' => $instanceName ,
]);
2019-03-10 22:41:42 -07:00
print ( " Status Code: " . $result [ '@metadata' ][ 'statusCode' ] . " , "
. $instanceName . " is " . $result [ 'state' ][ 'name' ] . " . \n " );
2019-01-28 16:49:11 -08:00
var_dump ( $result );
} catch ( AwsException $e ) {
// output error message if fails
2019-01-28 16:57:41 -08:00
echo $e -> getMessage () . " \n " ;
2019-01-28 16:49:11 -08:00
}
2024-02-05 10:49:20 -07:00
2019-01-28 16:49:11 -08:00
// snippet-end:[lightsail.php.get_instance_state.main]
// snippet-end:[lightsail.php.get_instance_state.complete]
// snippet-sourceauthor:[jschwarzwalder (AWS)]