SIGN IN SIGN UP

Welcome to the AWS Code Examples Repository. This repo contains code examples used in the AWS documentation, AWS SDK Developer Guides, and more. For more information, see the Readme.md file below.

0 0 0 Java
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
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.create_instance.complete]
// snippet-start:[lightsail.php.create_instance.import]
require 'vendor/autoload.php';
2019-01-28 16:49:11 -08:00
use Aws\Exception\AwsException;
2019-01-28 16:49:11 -08:00
// snippet-end:[lightsail.php.create_instance.import]
2019-01-28 16:49:11 -08:00
/**
* Create an 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
*/
2019-01-28 16:49:11 -08:00
//Create a Lightsail Client
// snippet-start:[lightsail.php.create_instance.main]
$client = new Aws\Lightsail\LightsailClient([
'profile' => 'default',
'version' => '2016-11-28',
'region' => 'us-east-2'
]);
2019-01-28 16:49:11 -08:00
$availabilityZone = 'us-east-2a';
$blueprintId = 'amazon_linux_2018_03_0_2';
$bundleId = 'nano_2_0';
$instanceName = 'AWS_SDK_PHP-Amazon_Linux';
2019-01-28 16:49:11 -08:00
try {
$result = $client->createInstances([
'availabilityZone' => $availabilityZone,
'blueprintId' => $blueprintId,
'bundleId' => $bundleId,
'instanceNames' => [$instanceName],
'tags' => [
[
'key' => 'SDK',
'value' => 'Made with AWS SDK for PHP',
],
[
'key' => 'Type',
'value' => 'Amazon Linux',
]
],
]);
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
}
2019-01-28 16:49:11 -08:00
// snippet-end:[lightsail.php.create_instance.main]
// snippet-end:[lightsail.php.create_instance.complete]
// snippet-sourceauthor:[jschwarzwalder (AWS)]