title: AWS SNS - Push to GCM
body: <p>I am attempting to use AWS SNS for push notifications for my app. I have successfully setup registation of individual endpoints ARN's using user info and regsitration ID.</p>
  
  <p>I can send an individual message via the console fine, however I can't seem to figure out how to send it programmatically (JAVA)</p>
  
  <p>Console way: (Working)</p>
  
  <p><a href="http://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-directmobile.html" rel="nofollow noreferrer">http://docs.aws.amazon.com/sns/latest/dg/mobile-push-send-directmobile.html</a></p>
  
  <p>Attempted way via JAVA:</p>
  
  <pre><code>private void publishToSNSEndpoint(String username) {
  
          // Find an entry of a users SNS registration and Endpoint ARN
          SNSPush pushConfig = snsPushService.findByUsername(username);
  
          //Get ARN to String
          String endpointARN = pushConfig.getSNSEnpointARN();
  
          //Generate SNS Push to user
          String message = "{\"title\":\"Test_Title\",\"description\":\"Test_Description\"}";
          PublishRequest publishRequest = new PublishRequest();
          publishRequest.setMessage(message);
          publishRequest.setTargetArn(endpointARN);
          PublishResult publish = client.publish(publishRequest);
  
          //print MessageId of message published to SNS topic
          System.out.println("MessageId - " + publish.getMessageId());
      }
  </code></pre>
  
  <p>This currently produces an error of the following:</p>
  
  <blockquote>
    <p>Using EndpointARN for use (Confirmed valid)  Invalid parameter:
    TargetArn Reason: No endpoint found for the target arn specified
    (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter;</p>
  </blockquote>
  
  <p>Using SNS Application ARN (Triple checked this is valid)</p>
  
  <blockquote>
    <p>Invalid parameter: TargetArn Reason:
    arn:aws:sns:ap-southeast-xxxxxxxxx-xxxx is not valid to publish to
    (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter;</p>
  </blockquote>
  
  <p>There is some documentation <a href="http://docs.aws.amazon.com/sns/latest/dg/mobile-push-gcm.html#SNSMobilePushGCMAPI" rel="nofollow noreferrer">here</a>. But it seems pretty old and doesn't work anymore.</p>
  
  <p><strong>My question is:</strong> How can I send Push notifications to an individual EndpointARN in AWS SNS programmatically using Java and the AWS SDK.</p>