Search

Feedback

Amazon Elastic Compute Cloud

This guide focuses on the AWS SDK for PHP client for Amazon Elastic Compute Cloud. This guide assumes that you have already downloaded and installed the AWS SDK for PHP. See Installation for more information on getting started.

Creating a client

First you need to create a client object using one of the following techniques.

Factory method

The easiest way to get up and running quickly is to use the Aws\Ec2\Ec2Client::factory() method and provide your credential profile (via the profile option), which identifies the set of credentials you want to use from your ~/.aws/credentials file (see Using the AWS credentials file and credential profiles).

A region parameter is required. You can find a list of available regions using the Regions and Endpoints reference.

use Aws\Ec2\Ec2Client;

$client = Ec2Client::factory(array(
    'profile' => '<profile in your aws credentials file>',
    'region'  => '<region name>'
));

You can provide your credential profile like in the preceding example, specify your access keys directly (via key and secret), or you can choose to omit any credential information if you are using AWS Identity and Access Management (IAM) roles for EC2 instances or credentials sourced from the AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables.

Note

The profile option and AWS credential file support is only available for version 2.6.1 of the SDK and higher. We recommend that all users update their copies of the SDK to take advantage of this feature, which is a safer way to specify credentials than explicitly providing key and secret.

Service builder

A more robust way to connect to Amazon Elastic Compute Cloud is through the service builder. This allows you to specify credentials and other configuration settings in a configuration file. These settings can then be shared across all clients so that you only have to specify your settings once.

use Aws\Common\Aws;

// Create a service builder using a configuration file
$aws = Aws::factory('/path/to/my_config.json');

// Get the client from the builder by namespace
$client = $aws->get('Ec2');

For more information about configuration files, see Configuring the SDK.

API Reference

Please see the Amazon Elastic Compute Cloud Client API reference for a details about all of the available methods, including descriptions of the inputs and outputs.

AcceptVpcPeeringConnection AllocateAddress
AllocateHosts AssignPrivateIpAddresses
AssociateAddress AssociateDhcpOptions
AssociateRouteTable AttachClassicLinkVpc
AttachInternetGateway AttachNetworkInterface
AttachVolume AttachVpnGateway
AuthorizeSecurityGroupEgress AuthorizeSecurityGroupIngress
BundleInstance CancelBundleTask
CancelConversionTask CancelExportTask
CancelImportTask CancelReservedInstancesListing
CancelSpotFleetRequests CancelSpotInstanceRequests
ConfirmProductInstance CopyImage
CopySnapshot CreateCustomerGateway
CreateDhcpOptions CreateFlowLogs
CreateImage CreateInstanceExportTask
CreateInternetGateway CreateKeyPair
CreateNatGateway CreateNetworkAcl
CreateNetworkAclEntry CreateNetworkInterface
CreatePlacementGroup CreateReservedInstancesListing
CreateRoute CreateRouteTable
CreateSecurityGroup CreateSnapshot
CreateSpotDatafeedSubscription CreateSubnet
CreateTags CreateVolume
CreateVpc CreateVpcEndpoint
CreateVpcPeeringConnection CreateVpnConnection
CreateVpnConnectionRoute CreateVpnGateway
DeleteCustomerGateway DeleteDhcpOptions
DeleteFlowLogs DeleteInternetGateway
DeleteKeyPair DeleteNatGateway
DeleteNetworkAcl DeleteNetworkAclEntry
DeleteNetworkInterface DeletePlacementGroup
DeleteRoute DeleteRouteTable
DeleteSecurityGroup DeleteSnapshot
DeleteSpotDatafeedSubscription DeleteSubnet
DeleteTags DeleteVolume
DeleteVpc DeleteVpcEndpoints
DeleteVpcPeeringConnection DeleteVpnConnection
DeleteVpnConnectionRoute DeleteVpnGateway
DeregisterImage DescribeAccountAttributes
DescribeAddresses DescribeAvailabilityZones
DescribeBundleTasks DescribeClassicLinkInstances
DescribeConversionTasks DescribeCustomerGateways
DescribeDhcpOptions DescribeExportTasks
DescribeFlowLogs DescribeHosts
DescribeIdFormat DescribeImageAttribute
DescribeImages DescribeImportImageTasks
DescribeImportSnapshotTasks DescribeInstanceAttribute
DescribeInstanceStatus DescribeInstances
DescribeInternetGateways DescribeKeyPairs
DescribeMovingAddresses DescribeNatGateways
DescribeNetworkAcls DescribeNetworkInterfaceAttribute
DescribeNetworkInterfaces DescribePlacementGroups
DescribePrefixLists DescribeRegions
DescribeReservedInstances DescribeReservedInstancesListings
DescribeReservedInstancesModifications DescribeReservedInstancesOfferings
DescribeRouteTables DescribeScheduledInstanceAvailability
DescribeScheduledInstances DescribeSecurityGroups
DescribeSnapshotAttribute DescribeSnapshots
DescribeSpotDatafeedSubscription DescribeSpotFleetInstances
DescribeSpotFleetRequestHistory DescribeSpotFleetRequests
DescribeSpotInstanceRequests DescribeSpotPriceHistory
DescribeSubnets DescribeTags
DescribeVolumeAttribute DescribeVolumeStatus
DescribeVolumes DescribeVpcAttribute
DescribeVpcClassicLink DescribeVpcClassicLinkDnsSupport
DescribeVpcEndpointServices DescribeVpcEndpoints
DescribeVpcPeeringConnections DescribeVpcs
DescribeVpnConnections DescribeVpnGateways
DetachClassicLinkVpc DetachInternetGateway
DetachNetworkInterface DetachVolume
DetachVpnGateway DisableVgwRoutePropagation
DisableVpcClassicLink DisableVpcClassicLinkDnsSupport
DisassociateAddress DisassociateRouteTable
EnableVgwRoutePropagation EnableVolumeIO
EnableVpcClassicLink EnableVpcClassicLinkDnsSupport
GetConsoleOutput GetPasswordData
ImportImage ImportInstance
ImportKeyPair ImportSnapshot
ImportVolume ModifyHosts
ModifyIdFormat ModifyImageAttribute
ModifyInstanceAttribute ModifyInstancePlacement
ModifyNetworkInterfaceAttribute ModifyReservedInstances
ModifySnapshotAttribute ModifySpotFleetRequest
ModifySubnetAttribute ModifyVolumeAttribute
ModifyVpcAttribute ModifyVpcEndpoint
MonitorInstances MoveAddressToVpc
PurchaseReservedInstancesOffering PurchaseScheduledInstances
RebootInstances RegisterImage
RejectVpcPeeringConnection ReleaseAddress
ReleaseHosts ReplaceNetworkAclAssociation
ReplaceNetworkAclEntry ReplaceRoute
ReplaceRouteTableAssociation ReportInstanceStatus
RequestSpotFleet RequestSpotInstances
ResetImageAttribute ResetInstanceAttribute
ResetNetworkInterfaceAttribute ResetSnapshotAttribute
RestoreAddressToClassic RevokeSecurityGroupEgress
RevokeSecurityGroupIngress RunInstances
RunScheduledInstances StartInstances
StopInstances TerminateInstances
UnassignPrivateIpAddresses UnmonitorInstances