Amazon-web-services – AWS SNS not sending Subscription Confirmation

amazon-snsamazon-web-services

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();
}

Best Answer

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.

Related Topic