diff --git a/README.md b/README.md index 35d89b7..24fcd5d 100644 --- a/README.md +++ b/README.md @@ -100,12 +100,19 @@ The snippet below shows the various configurable settings and their defaults. ```Ruby Rails.application.configure do config.active_elastic_job.process_jobs = ENV['PROCESS_ACTIVE_ELASTIC_JOBS'] == 'true' - config.active_elastic_job.aws_credentials = Aws::InstanceProfileCredentials.new + config.active_elastic_job.aws_credentials = lambda { Aws::InstanceProfileCredentials.new } # allows lambdas for lazy loading config.active_elastic_job.secret_key_base = Rails.application.secrets[:secret_key_base] cofnig.active_elastic_job.periodic_tasks_route = '/periodic_tasks'.freeze end ``` +If you want to provide the AWS credentials not by the EC2 instance prodfile, but via environment variables, you can do so: + ```Ruby + Rails.application.configure do + config.active_elastic_job.aws_credentials = Aws::Credentials.new(ENV['AWS_ACCESS_KEY_ID'], ENV['AWS_SECRET_ACCESS_KEY']) + end + ``` + ## FAQ A summary of frequently asked questions: ### What are the advantages in comparison to popular alternatives like Resque, Sidekiq or DelayedJob? diff --git a/lib/active_elastic_job/railtie.rb b/lib/active_elastic_job/railtie.rb index 9f27c22..03d80a7 100644 --- a/lib/active_elastic_job/railtie.rb +++ b/lib/active_elastic_job/railtie.rb @@ -2,7 +2,7 @@ module ActiveElasticJob class Railtie < Rails::Railtie config.active_elastic_job = ActiveSupport::OrderedOptions.new config.active_elastic_job.process_jobs = ENV['PROCESS_ACTIVE_ELASTIC_JOBS'] == 'true' - config.active_elastic_job.aws_credentials = Aws::InstanceProfileCredentials.new + config.active_elastic_job.aws_credentials = lambda { Aws::InstanceProfileCredentials.new } config.active_elastic_job.periodic_tasks_route = '/periodic_tasks'.freeze initializer "active_elastic_job.insert_middleware" do |app| diff --git a/lib/active_job/queue_adapters/active_elastic_job_adapter.rb b/lib/active_job/queue_adapters/active_elastic_job_adapter.rb index 54745c4..71d8921 100644 --- a/lib/active_job/queue_adapters/active_elastic_job_adapter.rb +++ b/lib/active_job/queue_adapters/active_elastic_job_adapter.rb @@ -169,7 +169,11 @@ def aws_sqs_client end def aws_sqs_client_credentials - config.aws_credentials + @aws_credentials ||= if config.aws_credentials.kind_of?(Proc) + config.aws_credentials.call + else + config.aws_credentials + end end def aws_region