Class: Bricolage::SNSDataSource

Inherits:
DataSource show all
Defined in:
lib/bricolage/snsdatasource.rb

Constant Summary

Constants inherited from DataSource

DataSource::CLASSES

Instance Attribute Summary collapse

Attributes inherited from DataSource

#context, #logger, #name

Instance Method Summary collapse

Methods inherited from DataSource

get_class, new_for_type, #open, #open_for_batch, #redshift_loader_source?

Constructor Details

#initialize(region:, topic_arn:, access_key_id: nil, secret_access_key: nil) ⇒ SNSDataSource

Returns a new instance of SNSDataSource.



10
11
12
13
14
15
16
17
# File 'lib/bricolage/snsdatasource.rb', line 10

def initialize(region:, topic_arn:, access_key_id: nil, secret_access_key: nil)
  @region = region
  @topic_arn = topic_arn
  @access_key_id = access_key_id
  @secret_access_key = secret_access_key
  @client = Aws::SNS::Client.new(region: region, access_key_id: access_key_id, secret_access_key: secret_access_key)
  @topic = Aws::SNS::Topic.new(topic_arn, client: @client)
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



20
21
22
# File 'lib/bricolage/snsdatasource.rb', line 20

def client
  @client
end

#regionObject (readonly)

Returns the value of attribute region.



19
20
21
# File 'lib/bricolage/snsdatasource.rb', line 19

def region
  @region
end

#topicObject (readonly)

Returns the value of attribute topic.



21
22
23
# File 'lib/bricolage/snsdatasource.rb', line 21

def topic
  @topic
end

Instance Method Details

#closeObject



35
36
# File 'lib/bricolage/snsdatasource.rb', line 35

def close
end

#publish(message) ⇒ Object Also known as: write



23
24
25
26
27
28
29
# File 'lib/bricolage/snsdatasource.rb', line 23

def publish(message)
  @topic.publish({ message: message })
rescue Aws::SNS::Errors::InvalidParameter => ex
  raise JobError, "bad SNS configuration (topic_arn=#{@topic_arn.inspect}): #{ex.message}"
rescue Aws::SNS::Errors::ServiceError => ex
  raise SNSException.wrap(ex)
end