Amazon Simple Queue Service (Amazon SQS) offers a reliable, highly scalable, hosted queue for storing messages. Amazon SQS can be used to applications that perform different tasks, without losing messages. Amazon SQS enables users to build an automated workflow.
Amazon Elastic Compute Cloud (EC2) is a web service that provides resizable compute capacity in the cloud. Amazon EC2 can be used for building applications that start small but can scale up rapidly as demand increases (Auto Scaling).
Amazon EC2 Features:
a) Increase or decrease capacity within minutes.
b) Make one, hundreds, or even thousands of server instances simultaneously.
c) Web Service API to control the scaling of instances depending on needs.
d) Pay only for what you use (Pay Per Use) pricing model.
Features of Amazon SQS:
a) Single Amazon SQS queue can be shared by multiple servers simultaneously.
b) Server that is processing a message can prevent other servers from processing the same message at the same time using temporarily “locking” a message. The server can specify the amount of time the message is locked. When the server is done processing the message, it should delete the message. If the server fails while processing the message, another server can get the message after the lockout period.
Pipeline processing with Amazon SQS:
a) Flexibility: Large monolithic server can be divided into multiple smaller servers without impacting the current system.
b) Piecemeal upgrades: Individual sub-components can be taken offline / upgraded without bringing the entire system down.
c) Tolerance to failures: Amazon SQS isolates sub-components from each other so the failure of one component does not impact the rest.
define('AWS_ACCESS_KEY_ID', '<access key>');
define('AWS_SECRET_ACCESS_KEY', '<secret key>');
define('SQS_TEST_MESSAGE', 'Welcome to SQS.');
$q = new SQSClient(AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, SQS_ENDPOINT);
// create Queue
$result = $q->CreateQueue(SQS_TEST_QUEUE);
// list Queue
$result = $q->ListQueues();
// send message to Queue
$messageId = $q->SendMessage(urlencode(SQS_TEST_MESSAGE));
// receive message from Queue
$messages = $q->ReceiveMessage();
echo 'Exception occurred: ', $e->getMessage(), "\n<br />\n";