3
votes

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
2
Can you see the topic if you run aws sns list-topicsDavid Webster
what is you default region set to in AWS cli? It might be a issue due to cross regionAatish Sai
you can use aws configure get region to see your default region set in AWS CLIAatish Sai
@DavidWebster yes, it shows the list of SNS topics.Chamin Wickramarathna
@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 questionAatish Sai

2 Answers

13
votes

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

3
votes

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