AWS SNS not sending Subscription Confirmation

11,257

Solution 1

You are always going to get "pending confirmation" as the response for the subscriptionArn. The confirmation process is asynchronously as a separate process. To make this even more confusing if you call to get a list of current subscriptions they will show an slightly different subscriptionArn of "PendingConfirmation" so you can not even match it later.

As far as being able to connect, I would try hitting an end point outside of AWS first. By default most AWS elements are very locked down and can not even connect to each other, so there is likely a security setting somewhere that needs to be changed to let SNS connect to your EC2. Which would be why you can connect to the EC2 outside of AWS, but your SNS service can not.

Also check to make sure the SNS and EC2 you are using are in the same region. It is a common cause of connection issues.

If you are using a host name to connect I would try using the direct IP to see if it gets through.

Solution 2

To troubleshoot, you should turn on the "Delivery status" reports in topic actions - https://docs.aws.amazon.com/sns/latest/dg/sns-msg-status.html. Then you will see why the confirmation message failed to be sent from AWS side.

On your EC2 instance side, on network level you must make sure that the port you are listening on is open from outside. There are several things: both making sure the port is open in firewall (Security groups settings), and making sure that the IP is reachable (i.e., make sure your VPC where the machine is located is publicly visible).

Share:
11,257
user1588766
Author by

user1588766

Updated on June 19, 2022

Comments

  • user1588766
    user1588766 almost 2 years

    I have setup AWS SNS setup with a topic say 'A'. I'm doing a subscribe to this SNS topic using Http (tried both manually using AWS console online and using Java Code). All I get is 'pending confirmation' in both cases. However SNS does not send the initial 'SubscriptionConfirmation' to the provided Url.

    Note that my endpoint is ready to receive http POST notification. When I manually do a POST from my side I see my servlet processing those Json I send. For some reason I receive nothing from AWS SNS.

    Note that my http end point that I used for subscribe is public facing so SNS should have no issue reaching it.

    Any inputs is appreciated.

    Here is my subscribe function.

    public String subscribe(String arn,String url) {
    
        if(arn == null || arn.isEmpty())
            arn = topicArn;
        SubscribeRequest subRequest = new SubscribeRequest(arn,"http",url);
        SubscribeResult  result = snsClient.subscribe(subRequest);
        //get request id for SubscribeRequest from SNS metadata
        if(result != null){
            LOGGER.info("SubscribeResult - " + result.toString());
        }
        LOGGER.info("SubscribeRequest - " + snsClient.getCachedResponseMetadata(subRequest));
        return result.toString();
    }