How to Confirm SNS Subscription and Fix PendingConfirmation Subscription

I have been trying to confirm SNS Subscription. But It just keep showing “PendingConfirmation”.

After searching in aws forum, I found that they send a POST request instantly. So I began searching for “Amazon Simple Notification Service Agent” in access log. But there were no records. I figure out that VSF was blocking the request.

So i create a another subscription with backend. Then I can see the request in access log. But still $_POST array was empty. After a number of trial and error, I found that i can only get the POST data using ‘php://input’. Here is the code that worked for me

$json = file_get_contents('php://input');
file_put_contents("file.json",json_encode($json));
$json = json_decode($json,1);

if (!empty($json)) {
    file_put_contents("file.json", 'not empty',FILE_APPEND);
    if($json['Type'] == 'SubscriptionConfirmation') {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $json['SubscribeURL']);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/37.0.2062.124 Safari/537.36');
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        // ENABLE HTTP POST
        $postresponse = curl_exec($ch);
        curl_close($ch);

    } 
}

About Zakir Hyder

This entry was written by .

18. December 2014 by Zakir Hyder
Categories: Server Management, Varnish, Web Development | Tags: , , , , , | Comments

Comments

  1. […] So i create a another subscription with backend. Then I can see the request in access log. But still $_POST array was empty. After a number of trial and error, I found that i can only get the POST data using ‘php://input’.  […]