• Home
  • Health
  • Software
  • Blog
  • sns

    Https Endpoint

    You can have SNS send a post request when it gets a notification. But Amazon may want you to verify that this is really your endpoint before it'll work.


    You can use something like this to verify it:

    https://github.com/npflood/AWS-SNS-HTTP-PHP-ENDPOINT/blob/master/receiver.php


    Or just a simple thing like this:

    <?php
    
    $res = file_get_contents("php://input");
    file_put_contents("logs/response.txt", $res . "\n", FILE_APPEND);
    

    Then you can read the response file for SubscribeUrl, e.g.:

    {
      "Type" : "SubscriptionConfirmation",
      "MessageId" : "165545c9-2a5c-472c-8df2-7ff2be2b3b1b",
      "Token" : "2336412f37f...",
      "TopicArn" : "arn:aws:sns:us-west-2:123456789012:MyTopic",
      "Message" : "You have chosen to subscribe to the topic arn:aws:sns:us-west-2:123456789012:MyTopic.\nTo confirm the subscription, visit the SubscribeURL included in this message.",
      "SubscribeURL" : "https://sns.us-west-2.amazonaws.com/?Action=ConfirmSubscription&TopicArn=arn:aws:sns:us-west-2:123456789012:MyTopic&Token=2336412f37...",
      "Timestamp" : "2012-04-26T20:45:04.751Z",
      "SignatureVersion" : "1",
      "Signature" : "EXAMPLEpH+...",
      "SigningCertURL" : "https://sns.us-west-2.amazonaws.com/SimpleNotificationService-f3ecfb7224c7233fe7bb5f59f96de52f.pem"
    }
    


    When you click "Confirm Subscription" in AWS SNS, it wants you to enter SubscribeUrl.