lib/logstash-logger/device/aws_stream.rb in logstash-logger-0.25.1 vs lib/logstash-logger/device/aws_stream.rb in logstash-logger-0.26.0

- old
+ new

@@ -1,12 +1,15 @@ -require 'aws-sdk' +begin + require 'aws-sdk-core' +rescue LoadError + require 'aws-sdk' +end module LogStashLogger module Device class AwsStream < Connectable - DEFAULT_REGION = 'us-east-1' DEFAULT_STREAM = 'logstash' @stream_class = nil @recoverable_error_codes = [] @@ -16,13 +19,13 @@ attr_accessor :aws_region, :stream def initialize(opts) super - @access_key_id = opts[:aws_access_key_id] || ENV['AWS_ACCESS_KEY_ID'] - @secret_access_key = opts[:aws_secret_access_key] || ENV['AWS_SECRET_ACCESS_KEY'] - @aws_region = opts[:aws_region] || DEFAULT_REGION + @access_key_id = opts[:aws_access_key_id] + @secret_access_key = opts[:aws_secret_access_key] + @aws_region = opts[:aws_region] @stream = opts[:stream] || DEFAULT_STREAM end def transform_message(message) fail NotImplementedError @@ -39,13 +42,13 @@ def get_response_records(resp) fail NotImplementedError end def connect - @io = self.class.stream_class.new( - region: @aws_region, - credentials: ::Aws::Credentials.new(@access_key_id, @secret_access_key) - ) + client_opts = {} + client_opts[:credentials] = Aws::Credentials.new(@access_key_id, @secret_access_key) unless @access_key_id == nil || @secret_access_key == nil + client_opts[:region] = @aws_region unless @aws_region == nil + @io = self.class.stream_class.new(client_opts) end def with_connection connect unless connected? yield