15

I am working with AWS SNS services and completed the initial setup as the AWS documentation. I just needed to test it using aws-cli. So I used the following command to publish a test message to SNS topic from my local PC.

aws sns publish --topic-arn "arn:aws:sns:us-east-1:xxxxxxxxxxx:test-notification-service" --message "Hello, from SNS"

However, I got stuck on the following generic error. It just says Invalid Parameter. I have configured the ~/.aws/credentials as needed.

An error occurred (InvalidParameter) when calling the Publish operation: Invalid parameter: TopicArn
7
  • Can you see the topic if you run aws sns list-topics Commented Jan 16, 2019 at 13:01
  • 2
    what is you default region set to in AWS cli? It might be a issue due to cross region Commented Jan 16, 2019 at 13:08
  • you can use aws configure get region to see your default region set in AWS CLI Commented Jan 16, 2019 at 13:09
  • @DavidWebster yes, it shows the list of SNS topics. Commented Jan 17, 2019 at 5:55
  • 1
    @ChaminWickramarathna sometimes the error message are tricky on AWS CLI and I knew it since it happed to me aswell. I will post the solution as an answer. Feel free to mark as correct to help other if they stumble upon this question Commented Jan 17, 2019 at 10:57

3 Answers 3

27

The issue is due to cross-region. You AWS-CLI default region might be different to the region your SNS service location.

Check your AWS-CLI location and make sure you are in the same region as your SNS.

To check your region in AWS CLI use:

aws configure get region

To configure your AWS region you can use the command:

aws configure set region <region-name>

https://docs.aws.amazon.com/cli/latest/reference/configure/set.html

Sign up to request clarification or add additional context in comments.

1 Comment

If anyone using aws-sdk in NodeJS is facing this error, then check whether every initialization of the SDK has the same value for region in its config property.
10

You can just add region parameter --region us-east-1 to your command:

aws sns publish --topic-arn "arn:aws:sns:us-east-1:xxxxxxxxxxx:test-notification-service" --message "Hello, from SNS" --region us-east-1

Comments

-2

In my case, the setTopicArn didn't work.

From debugging, I've found the setTargetArn, use it and worked.

String content = fileName + ":" + percentage;

PublishRequest publishRequest = new PublishRequest();

publishRequest.setTargetArn(config.getTopicArn());
publishRequest.setMessage(content);
publishRequest.setSubject("Resize");

snsClient.publish(publishRequest);

I'm using springboot and aws sdk

<dependency>
    <groupId>com.amazonaws</groupId>
    <artifactId>aws-java-sdk-sns</artifactId>
    <version>1.12.772</version>
</dependency>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.