Invalid Parameter: Topic Name Error when publishing to AWS SNS arn endpoint

11,073

Solution 1

You should use TargetArn instead of TopicArn which is the first parameter of PublishRequest constructor.

PublishRequest pr = new PublishRequest();
pr.TargetArn = "arn:aws:sns:us-east-1:XXX:endpoint/APNS_SANDBOX/XXX/XXX-XXX-XXX-XXX";
pr.Message = message;

(maybe it is too late to answer lol)

Solution 2

The error message is a bit confusing. If you provide the wrong topic ARN, you get error message saying Invalid Parameter: Topic Name as well.

From what you posted, it looks like you might have used the subscription ARN, instead of topic ARN. Topic ARN format looks like this arn:aws:sns:AWS_REGION:AWS_ACCOUNT_NUMBER:TOPIC_NAME.

Solution 3

Your problem was this: String message = "{"APNS_SANDBOX":"{\"aps\":{\"type\":\"XXX\",\"email\":\"[email protected]\",\"alert\":\"some alert\"}}"}";

instead it should have been: String message = "{"APNS_SANDBOX":"{\"aps\":{\"type\":\"XXX\",\"email\":\"[email protected]\",\"alert\":\"somealert\"}}"}";

You cant put name of the topic with spaces. So "some alert" will be rejected. "somealert" will be accepted.

In case someone else stumbles upon this problem.

Share:
11,073
devok
Author by

devok

Updated on June 27, 2022

Comments

  • devok
    devok almost 2 years

    In Java, I am trying to publish a AWS SNS message to a specific ARN endpoint using the following code:

    import com.amazonaws.auth.BasicAWSCredentials;
    import com.amazonaws.regions.Region;
    import com.amazonaws.regions.Regions;
    import com.amazonaws.services.sns.AmazonSNS;
    import com.amazonaws.services.sns.AmazonSNSClient;
    import com.amazonaws.services.sns.model.PublishRequest;
    import com.amazonaws.services.sns.model.PublishResult;
    
    ...
    
    AmazonSNS snsClient = new AmazonSNSClient(new BasicAWSCredentials(System.getenv("AWS_KEY"), System.getenv("AWS_SECRET")));
    
    snsClient.setRegion(Region.getRegion(Regions.US_EAST_1));
    
    String message = "{\"APNS_SANDBOX\":\"{\\\"aps\\\":{\\\"type\\\":\\\"XXX\\\",\\\"email\\\":\\\"[email protected]\\\",\\\"alert\\\":\\\"some alert\\\"}}\"}";
    
    PublishResult pr = snsClient.publish(new PublishRequest("arn:aws:sns:us-east-1:XXX:endpoint/APNS_SANDBOX/XXX/XXX-XXX-XXX-XXX", message));
    

    I am consistently getting the following error message:

    Invalid parameter: Topic Name (Service: AmazonSNS; Status Code: 400; Error Code: InvalidParameter; Request ID: XXX

    Any idea on this?

    I can publish to the ARN endpoint with no issues from the SNS console and I have tried different variations of the message

  • Slobodan Djipalo
    Slobodan Djipalo over 3 years
    Ok. I`ll keep that in mind in the future. Thanks for the tip.