Last active
November 21, 2019 15:26
-
-
Save manishval/f8e07b3a867462e1831ca963e02010cd to your computer and use it in GitHub Desktop.
Export AWS SNS application endpoints
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 | |
endpoints = [] | |
while fetch_more | |
attributes = { | |
platform_application_arn: 'PLATFORM_APPLICATION_ARN' | |
} | |
attributes = attributes.merge(next_token: next_token) if next_token.present? | |
response = @client.list_endpoints_by_platform_application(attributes) | |
response[:endpoints].each do |endpoint| | |
endpoints << endpoint.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/endpoints.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