Installation guide
RemovePermission SetEndpointAttributes
SetPlatformApplicationAttributes SetSubscriptionAttributes
SetTopicAttributes Subscribe
Unsubscribe
Amazon Simple Queue Service
This guide focuses on the AWS SDK for PHP client for Amazon Simple Queue Service. 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\Sqs\SqsClient::factory() method and
provide your credentials (key and secret).
A region parameter is also required and must be set to one of the following values: us-east-1,
ap-northeast-1, sa-east-1, ap-southeast-1, ap-southeast-2, us-west-2, us-gov-west-1,
us-west-1, cn-north-1, eu-west-1
use Aws\Sqs\SqsClient;
$client = SqsClient::factory(array(
'key' => '<aws access key>',
'secret' => '<aws secret key>',
'region' => '<region name>'
));
You can provide your access keys like in the preceding example, or you can choose to omit them 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.
Service builder
A more robust way to connect to Amazon Simple Queue Service 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('Sqs');
Creating a queue
Now, let's create a queue. You can create a standard queue by just providing a name. Make sure to get the queue's
URL from the result, since the queue URL is the unique identifier used to specify the queue in order to send and
receive messages.
$result = $client->createQueue(array('QueueName' => 'my-queue'));
$queueUrl = $result->get('QueueUrl');
You can also set attributes on your queue when you create it.
Amazon Simple Queue Service
118