Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Install the gem first: gem install aws-sdk-sns
- require 'aws-sdk-sns'
- Aws.config.update({
- region: 'eu-west-1',
- credentials: Aws::Credentials.new('aws_access_key_id', 'aws_secret_access_key')
- })
- def list_topics
- sns.topics.each do |topic|
- puts topic.arn
- end
- end
- def create_topic(name:)
- sns.create_topic(name: name)
- end
- def list_topic_subscriptions(topic)
- topic.subscriptions.each do |s|
- puts s.attributes['Endpoint']
- end
- end
- def sns
- @sns ||= Aws::SNS::Resource.new
- end
- topic = create_topic(name: 'my-first-topic')
- # topic = sns.topic('arn:aws:sns:eu-west-1:account-id:topicname')
- topic.subscribe({
- protocol: 'email',
- endpoint: 'foo@mailinator.com'
- })
- list_topics
- list_topic_subscriptions(topic)
- topic.publish({
- message: 'Hello! Check your emails.'
- })
Add Comment
Please, Sign In to add comment