title: AWS SQS SNS protocol using PHP
body: <p>The following code allows me to send <code>SNS</code> with (queue) <code>SQS</code> but i cant seem to choose the protocol like in amazons management console
  <img src="https://i.stack.imgur.com/QpiOs.jpg" alt="enter image description here"></p>
  
  <p><br/>
  * the keys are all random strings</p>
  
  <pre><code>&lt;?php
  require_once('sdk-1.5.6.2/sdk.class.php');  
  $AWS_KEY = "6VVWTU4JDAAKHYB1C3ZN";
  $AWS_SECRET_KEY = "GMSCUD8C0QA1QLV9Y3RP2IAKDIZSCHRGKEJSXZ4F";
  
  //create a new SQS queue and grab the queue URL
  $sqs = new AmazonSQS(array( "key" =&gt; $AWS_KEY, "secret" =&gt; $AWS_SECRET_KEY ));
  $response = $sqs-&gt;create_queue('test-topic-queue');
  $queue_url = (string) $response-&gt;body-&gt;CreateQueueResult-&gt;QueueUrl;
  $queue_arn = 'arn:aws:sqs:us-east-1:ENCQ8gqrAcXv:test-topic-queue';
  
  //create a new SNS topic and grab the topic ARN.
  $sns = new AmazonSNS(array( "key" =&gt; $AWS_KEY, "secret" =&gt; $AWS_SECRET_KEY ));
  $response = $sns-&gt;create_topic('test-topic');
  $topic_arn = (string) $response-&gt;body-&gt;CreateTopicResult-&gt;TopicArn;
  
  //Then give the SNS topic the permission to send messages to the SQS queue. ** allow all principals. SNS doesn't send from your account ID -- it has its own account ID that it sends from.
  $queue_url = 'https://sqs.us-east-1.amazonaws.com/ENCQ8gqrAcXv/test-topic-queue';
  $queue_arn = 'arn:aws:sqs:us-east-1:ENCQ8gqrAcXv:test-topic-queue';
  $topic_arn = 'arn:aws:sns:us-east-1:ENCQ8gqrAcXv:test-topic';
  
  $policy = new CFPolicy($sqs, array(
          'Version' =&gt; '2008-10-17',
          'Id' =&gt; 'sampleId',
          'Statement' =&gt; array(
                  array(
                          'Resource' =&gt; $queue_arn,
                          'Effect' =&gt; 'Allow',
                          'Sid' =&gt; 'rule1',
                          'Action' =&gt; 'sqs:*',
                          'Condition' =&gt; array(
                                  'StringEquals' =&gt; array(
                                          'aws:SourceArn' =&gt; $topic_arn
                                  )
                          ),
                          'Principal' =&gt; array(
                                  'AWS' =&gt; '*'
                          )
                  )
          )
  ));
  
  $response = $sqs-&gt;set_queue_attributes($queue_url, array(
          array('Name' =&gt; 'Policy', 'Value' =&gt; $policy-&gt;get_json())
  ));
  
  
  //then subscribe the SQS queue to the SNS topic and grab the subscription ARN.
  $queue_arn = 'arn:aws:sqs:us-east-1:ENCQ8gqrAcXv:test-topic-queue';
  $topic_arn = 'arn:aws:sns:us-east-1:ENCQ8gqrAcXv:test-topic';
  $response = $sns-&gt;subscribe($topic_arn, 'sqs', $queue_arn);
  
  
  
  
  // normally here is where you would choose the protocol but this example sends this to SQS
  // subscribe ( $topic_arn, $protocol, $endpoint, $opt ) 
  
  
  
  
  $subscription_arn = (string) $response-&gt;body-&gt;SubscribeResult-&gt;SubscriptionArn;
  //view the list of subscriptions to verify.
  $topic_arn = 'arn:aws:sns:us-east-1:ENCQ8gqrAcXv:test-topic';
  
  $q = new CFBatchRequest(200);
  for ($i = 0; $i &lt; 1000; $i++)
  {
          $sns-&gt;batch($q)-&gt;publish($topic_arn, 'Hello world! ' . time());
  }
  $response = $sns-&gt;batch($q)-&gt;send();
  
  
  //receive messages from the queue.
  $queue_url = 'https://sqs.us-east-1.amazonaws.com/ENCQ8gqrAcXv/test-topic-queue';
  $response = $sqs-&gt;receive_message($queue_url, array(
          'MaxNumberOfMessages' =&gt; 10,
  ));
  print_r($response); 
  
  
  // delete SQS queue
  $queue_url = 'https://sqs.us-east-1.amazonaws.com/ENCQ8gqrAcXv/test-topic-queue'; 
  $response = $sqs-&gt;delete_queue($queue_url);
  
  ?&gt;
  </code></pre>
  
  <p><br/><br/>
  <strong>question:</strong> where would i choose the protocol? <br/>
  <a href="http://docs.amazonwebservices.com/AWSSDKforPHP/latest/index.html#i=AmazonSNS" rel="nofollow noreferrer">this link</a> says that <code>subscribe()</code> is where <code>protocol</code> is defined but the above example sends that to <code>SQS</code> </p>