I started to work with AWS SNS to send push notifications to my app. Today, to get a topic that I want to send push notifications to, I need to load all topics – using SNS client function listTopics() - and check each topic to see if the ARN has the name of the topic that I'm looking for.
I think that it's a very inefficient way to get a topic ARN, and I'd like to know if there is a most efficient way to get this information, like a function getTopicByName or something else.
If not, I'd like to know if ARN is immutable, and if can I store the topic ARN on my database?
Thanks.
I don't know of any way to look up an SNS topic by name.
The ARN is immutable. It will not change for the life of the SNS topic. In particular, according to the documentation an ARN for an SNS topic is in the following format:
arn:aws:sns:region:account-id:topicname
So the only way for the SNS topic's ARN to change would be to change the name (in which case your lookup by name would also break), or delete the topic and recreate it in a new region or in an entirely different account, in which case it would not really the same topic anymore.
If you know the topic already exists or you don't care if it gets created, then a much more direct approach is simply to call CreateTopic
. Given a name, CreateTopic
will return the existing topic, including the ARN.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With