Created
April 20, 2017 12:15
-
-
Save manishval/3aa5d48d1a9c58fbb51190e02b5bd62b to your computer and use it in GitHub Desktop.
Export AWS SNS Topic Subscriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@client = AWS::SNS::Client.new( | |
region: 'AWS_SNS_REGION', | |
access_key_id: 'AWS_SNS_KEY_ID', | |
secret_access_key: 'AWS_SNS_ACCESS_KEY' | |
) | |
fetch_more = true | |
next_token = nil | |
subscriptions = [] | |
while fetch_more | |
attributes = { | |
topic_arn: 'TOPIC_ARN' | |
} | |
attributes = attributes.merge(next_token: next_token) if next_token.present? | |
response = @client.list_subscriptions_by_topic(attributes) | |
response[:subscriptions].each do |subscription| | |
subscriptions << subscription.to_h | |
end | |
if response[:next_token].present? | |
next_token = response[:next_token] | |
else | |
fetch_more = false | |
end | |
end | |
require 'json' | |
File.open("#{Rails.root.to_s}/public/subscriptions.json","w") do |f| | |
f.write(endpoints.to_json) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment