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

Adds the ability to send to a different account id's queue. #30

Closed
wants to merge 4 commits into from
Closed
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: 10 additions & 1 deletion docs/index.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,15 @@ URI to proxy server if required
The name of the target SQS queue. Note that this is just the name of the
queue, not the URL or ARN.

[id="plugins-{type}s-{plugin}-queue_owner_aws_account_id"]
===== `queue_owner_aws_account_id`

* Value type is <<string,string>>
* There is no default value for this setting.

The owning account id of the target SQS queue. IAM permissions need to be
configured on both accounts to function.

[id="plugins-{type}s-{plugin}-region"]
===== `region`

Expand Down Expand Up @@ -228,4 +237,4 @@ The AWS Session token for temporary credential
[id="plugins-{type}s-{plugin}-common-options"]
include::{include_path}/{type}.asciidoc[]

:default_codec!:
:default_codec!:
13 changes: 10 additions & 3 deletions lib/logstash/outputs/sqs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ class LogStash::Outputs::SQS < LogStash::Outputs::Base
# queue, not the URL or ARN.
config :queue, :validate => :string, :required => true

# Account ID of the AWS account which owns the queue. Note IAM permissions
# need to be configured on both accounts to function.
config :queue_owner_aws_account_id, :validate => :string, :required => false

public
def register
@sqs = Aws::SQS::Client.new(aws_options_hash)
Expand All @@ -98,9 +102,12 @@ def register
end

begin
@logger.debug('Connecting to SQS queue', :queue => @queue, :region => region)
@queue_url = @sqs.get_queue_url(:queue_name => @queue)[:queue_url]
@logger.info('Connected to SQS queue successfully', :queue => @queue, :region => region)
params = { queue_name: @queue }
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this closely resembles Chris' suggestion, but I felt it was a good balance of simplicity and fulfilling requirements. Note I did change the logging message to match the exact AWS attribute "queue_name" over the previously used "queue".

params[:queue_owner_aws_account_id] = @queue_owner_aws_account_id if @queue_owner_aws_account_id

@logger.debug('Connecting to SQS queue', params.merge(region: region))
@queue_url = @sqs.get_queue_url(params)[:queue_url]
@logger.info('Connected to SQS queue successfully', params.merge(region: region))
rescue Aws::SQS::Errors::ServiceError => e
@logger.error('Failed to connect to SQS', :error => e)
raise LogStash::ConfigurationError, 'Verify the SQS queue name and your credentials'
Expand Down
8 changes: 8 additions & 0 deletions spec/integration/outputs/sqs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@
end
end

context 'with a nonpermissive account id' do
let(:config) { super.merge('queue_owner_aws_account_id' => '123456789012')}

it 'raises a configuration error' do
expect { subject.register }.to raise_error(LogStash::ConfigurationError)
end
end

context 'with valid configuration' do
it 'does not raise an error' do
expect { subject.register }.not_to raise_error
Expand Down