Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add queue_aws_account_id option #38

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions lib/logstash/inputs/sqs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ class LogStash::Inputs::SQS < LogStash::Inputs::Threadable
# Name of the SQS Queue name to pull messages from. Note that this is just the name of the queue, not the URL or ARN.
config :queue, :validate => :string, :required => true

# Account ID of the AWS account which owns the queue.
config :queue_aws_account_id, :validate => :string, :required => false

Copy link
Contributor

@ph ph Aug 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use the same naming as the AWS' official documentation and call it queue_owner_aws_account_id, we will need to change the other reference in the code.

Interesting links:
http://docs.aws.amazon.com/AWSSimpleQueueService/latest/APIReference/API_GetQueueUrl.html
http://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/acp-overview.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will also need to add new user documentation in the static asciidoc file at https://github.com/logstash-plugins/logstash-input-sqs/blob/master/docs/index.asciidoc

# Name of the event field in which to store the SQS message ID
config :id_field, :validate => :string

Expand All @@ -99,14 +102,18 @@ class LogStash::Inputs::SQS < LogStash::Inputs::Threadable

def register
require "aws-sdk"
@logger.info("Registering SQS input", :queue => @queue)
@logger.info("Registering SQS input", :queue => @queue, :queue_aws_account_id => @queue_aws_account_id)

setup_queue
end

def setup_queue
aws_sqs_client = Aws::SQS::Client.new(aws_options_hash)
queue_url = aws_sqs_client.get_queue_url(:queue_name => @queue)[:queue_url]
if @queue_aws_account_id
queue_url = aws_sqs_client.get_queue_url({:queue_name => @queue, :queue_owner_aws_account_id => @queue_aws_account_id})[:queue_url]
else
queue_url = aws_sqs_client.get_queue_url(:queue_name => @queue)[:queue_url]
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move that logic block into his own method maybe call it queue_url?

@poller = Aws::SQS::QueuePoller.new(queue_url, :client => aws_sqs_client)
rescue Aws::SQS::Errors::ServiceError => e
@logger.error("Cannot establish connection to Amazon SQS", :error => e)
Expand Down
18 changes: 18 additions & 0 deletions spec/inputs/sqs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,24 @@
expect { subject.register }.not_to raise_error
end

context "when queue_aws_account_id option is specified" do
let(:queue_aws_account_id) { "123456789012" }
let(:config) do
{
"region" => "us-east-1",
"access_key_id" => "123",
"secret_access_key" => "secret",
"queue" => queue_name,
"queue_aws_account_id" => queue_aws_account_id
}
end
it "passes the option to sqs client" do
expect(Aws::SQS::Client).to receive(:new).and_return(mock_sqs)
expect(mock_sqs).to receive(:get_queue_url).with({ :queue_name => queue_name, :queue_owner_aws_account_id => queue_aws_account_id }).and_return({:queue_url => queue_url })
expect { subject.register }.not_to raise_error
end
end

context "when interrupting the plugin" do
before do
expect(Aws::SQS::Client).to receive(:new).and_return(mock_sqs)
Expand Down