Guest User

Untitled

a guest
Jun 23rd, 2018
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.78 KB | None | 0 0
  1. # Install the gem first: gem install aws-sdk-sns
  2. require 'aws-sdk-sns'
  3.  
  4. Aws.config.update({
  5. region: 'eu-west-1',
  6. credentials: Aws::Credentials.new('aws_access_key_id', 'aws_secret_access_key')
  7. })
  8.  
  9. def list_topics
  10. sns.topics.each do |topic|
  11. puts topic.arn
  12. end
  13. end
  14.  
  15. def create_topic(name:)
  16. sns.create_topic(name: name)
  17. end
  18.  
  19. def list_topic_subscriptions(topic)
  20. topic.subscriptions.each do |s|
  21. puts s.attributes['Endpoint']
  22. end
  23. end
  24.  
  25. def sns
  26. @sns ||= Aws::SNS::Resource.new
  27. end
  28.  
  29. topic = create_topic(name: 'my-first-topic')
  30. # topic = sns.topic('arn:aws:sns:eu-west-1:account-id:topicname')
  31.  
  32. topic.subscribe({
  33. protocol: 'email',
  34. endpoint: 'foo@mailinator.com'
  35. })
  36.  
  37. list_topics
  38.  
  39. list_topic_subscriptions(topic)
  40.  
  41. topic.publish({
  42. message: 'Hello! Check your emails.'
  43. })
Add Comment
Please, Sign In to add comment