# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. # SPDX-License-Identifier: Apache-2.0 # Purpose: # show_topics.rb demonstrates how to list Amazon Simple Notification Service (SNS) topics using # the AWS SDK for Ruby. # Inputs: # - REGION # snippet-start:[sns.Ruby.showTopics] require 'aws-sdk-sns' # v2: require 'aws-sdk' def list_topics?(sns_client) sns_client.topics.each do |topic| puts topic.arn rescue StandardError => e puts "Error while listing the topics: #{e.message}" end end def run_me region = 'REGION' sns_client = Aws::SNS::Resource.new(region: region) puts 'Listing the topics.' return if list_topics?(sns_client) puts 'The bucket was not created. Stopping program.' exit 1 end # Example usage: run_me if $PROGRAM_NAME == __FILE__ # snippet-end:[sns.Ruby.showTopics]