If the theme is already available, you can use the "createTopic" method as follows. With this, if the requester already owns a topic with the specified name, this ARN topic is returned without creating a new topic. In the AWS Java SDK, the code will look like this.
AWSCredentialsProvider provider = new ProfileCredentialsProvider(); AmazonSNS sns = AmazonSNSClientBuilder.standard().withCredentials(provider).build(); CreateTopicResult createRes = sns.createTopic("HelloTopic");
Then, using CreateTopicResult, you can get the ARN of the topic and post a message
sns.publish(new PublishRequest(createRes.getTopicArn(), "Hello World"));
source share