AWS SNS Invalid parameter TopicArn Error

Read this post if you want to solve the AWS SNS Invalid parameter TopicArn error. First off! This AWS SNS Topic ARN message is quite misleading. Read below to see why.

You should see an error similar to this one:

An error occurred (InvalidParameter) when calling the Publish operation: Invalid parameter: TopicArn

How to find the error

This error will display one of the following messages:

  • The “An error occurred (InvalidParameter) when calling the Publish operation: Invalid parameter: TopicArn” error will display in the Linux console when you run the AWS CLI SNS Publish command via Bash.
  • The “botocore.exceptions.ClientError: An error occurred (InvalidParameter) when calling the Publish operation: Invalid parameter: TopicArn” error will display as an exception when you run the AWS CLI SNS Publish command via BotoCore.
  • Similar error messages exist for other platforms.

What are the possible cause(s)

The following cause(s) have been identified:

  • You are using an incorrect topic for the region. For example, you are using us-west-2, but default your SNS client is pointing to us-east-1.

Analysing the cause(s)

Check your AWS default region that is configured in your code or via AWS Configure.

Example of “AWS Configure” response in Linux:

ubuntu@server:/home/ubuntu$ aws configure
AWS Access Key ID [****************WJNA]:
AWS Secret Access Key [****************MbrW]:
Default region name [us-east-1]:
Default output format [json]:

Example Bash code that calls the AWS CLI SNS Publish Command:

/usr/bin/aws sns publish --topic-arn arn:aws:sns:ap-southeast-2:111111111111:ap-dev-status --message "Hello world!"

Note that the AWS configure command mentions the default region as “us-east-1”.

The TopicARN is located in “ap-southeast-2”. You will thus see the “Invalid parameter: TopicArn” error when you publish an SNS message to anywhere other than “ap-southeast-2”.

The reason for this is because the Topic ARN does not exist in ” us-east-1″.

Solution(s) for this issue

Solve this error using one of the following solution(s):

You can either change the default region by using AWS Configure.

See an example below when using Linux Bash:

ubuntu@server:/home/ubuntu$ aws configure
AWS Access Key ID [****************WJNA]:
AWS Secret Access Key [****************MbrW]:
Default region name [ap-southeast-2]:
Default output format [json]:

Or you can be explicit and specify the region in the AWS SNS Publish call:

An example of the Bash AWS CLI SNS Publish Call via PHP:

$SnSclient = new SnsClient([
    'profile' => 'default',
    'region' => 'us-east-1',
    'version' => '2010-03-31'
]);

An example of the Bash AWS CLI SNS Publish Call via Bash:

/usr/bin/aws sns publish --region ap-southeast-2 --topic-arn arn:aws:sns:ap-southeast-2:111111111111:ap-dev-status --message "$MSG"

Add the “– region” parameter and specify the region of the Topic ARN.

Wrapping up

How did you solve this issue? Let Anto Online know in the comments below.

You may also be interested in

About Anto Online

Anto, a seasoned technologist with over two decades of experience, has traversed the tech landscape from Desktop Support Engineer to enterprise application consultant, specializing in AWS serverless technologies. He guides clients in leveraging serverless solutions while passionately exploring cutting-edge cloud concepts beyond his daily work. Anto's dedication to continuous learning, experimentation, and collaboration makes him a true inspiration, igniting others' interest in the transformative power of cloud computing.

View all posts by Anto Online

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.