Module: Aws::Rails

Defined in:
lib/aws/rails/railtie.rb,
lib/aws-sdk-rails.rb,
lib/aws/rails/ses_mailer.rb,
lib/aws/rails/sesv2_mailer.rb,
lib/aws/rails/notifications.rb,
lib/aws/rails/sqs_active_job.rb,
lib/aws/rails/action_mailbox/rspec.rb,
lib/aws/rails/action_mailbox/engine.rb,
lib/aws/rails/sqs_active_job/poller.rb,
lib/aws/rails/sqs_active_job/executor.rb,
lib/aws/rails/action_mailbox/s3_client.rb,
lib/aws/rails/sqs_active_job/job_runner.rb,
lib/aws/rails/action_mailbox/rspec/email.rb,
lib/aws/rails/sqs_active_job/configuration.rb,
lib/aws/rails/sqs_active_job/deduplication.rb,
lib/aws/rails/sqs_active_job/lambda_handler.rb,
lib/aws/rails/action_mailbox/sns_notification.rb,
lib/aws/rails/action_mailbox/sns_message_verifier.rb,
lib/aws/rails/middleware/ebs_sqs_active_job_middleware.rb,
lib/aws/rails/action_mailbox/rspec/subscription_confirmation.rb

Overview

Use the Rails namespace.

Defined Under Namespace

Modules: ActionMailbox, SqsActiveJob Classes: EbsSqsActiveJobMiddleware, Notifications, Railtie, SesMailer, Sesv2Mailer

Constant Summary collapse

VERSION =
File.read(File.expand_path('../VERSION', __dir__)).strip
Mailer =

This is for backwards compatibility after introducing support for SESv2. The old mailer is now replaced with the new SES (v1) mailer.

Aws::Rails::SesMailer

Class Method Summary collapse

Class Method Details

.add_action_mailer_delivery_method(name, client_options = {}) ⇒ Object

This is called automatically from the SDK’s Railtie, but can be manually called if you want to specify options for building the Aws::SES::Client or Aws::SESV2::Client.

Parameters:

  • name (Symbol)

    The name of the ActionMailer delivery method to register, either :ses or :sesv2.

  • client_options (Hash) (defaults to: {})

    The options you wish to pass on to the Aws::SES::Client initialization method.



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/aws/rails/railtie.rb', line 35

def self.add_action_mailer_delivery_method(name, client_options = {})
  ActiveSupport.on_load(:action_mailer) do
    case name
    when :ses
      add_delivery_method(name, Aws::Rails::SesMailer, client_options)
    when :sesv2
      add_delivery_method(name, Aws::Rails::Sesv2Mailer, client_options)
    else
      raise ArgumentError, "Unknown action mailer delivery method: #{name}"
    end
  end
end

.add_sqsd_middleware(app) ⇒ Object

Register a middleware that will handle requests from the Elastic Beanstalk worker SQS Daemon. This will only be added in the presence of the AWS_PROCESS_BEANSTALK_WORKER_REQUESTS environment variable. The expectation is this variable should only be set on EB worker environments.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/aws/rails/railtie.rb', line 81

def self.add_sqsd_middleware(app)
  is_eb_worker_hosted = Aws::Util.str_2_bool(ENV['AWS_PROCESS_BEANSTALK_WORKER_REQUESTS'].to_s.downcase)

  return unless is_eb_worker_hosted

  if app.config.force_ssl
    # SQS Daemon sends requests over HTTP - allow and process them before enforcing SSL.
    app.config.middleware.insert_before(ActionDispatch::SSL, Aws::Rails::EbsSqsActiveJobMiddleware)
  else
    app.config.middleware.use(Aws::Rails::EbsSqsActiveJobMiddleware)
  end
end

.instrument_sdk_operationsObject

Adds ActiveSupport Notifications instrumentation to AWS SDK client operations. Each operation will produce an event with a name: <operation>.<service>.aws. For example, S3’s put_object has an event name of: put_object.S3.aws



68
69
70
71
72
73
74
75
76
# File 'lib/aws/rails/railtie.rb', line 68

def self.instrument_sdk_operations
  Aws.constants.each do |c|
    m = Aws.const_get(c)
    if m.is_a?(Module) && m.const_defined?(:Client) &&
       m.const_get(:Client).superclass == Seahorse::Client::Base
      m.const_get(:Client).add_plugin(Aws::Rails::Notifications)
    end
  end
end

.log_to_rails_loggerObject

Configures the AWS SDK for Ruby’s logger to use the Rails logger.



49
50
51
52
# File 'lib/aws/rails/railtie.rb', line 49

def self.log_to_rails_logger
  Aws.config[:logger] = ::Rails.logger
  nil
end

.use_rails_encrypted_credentialsObject

Configures the AWS SDK with credentials from Rails encrypted credentials.



55
56
57
58
59
60
61
62
# File 'lib/aws/rails/railtie.rb', line 55

def self.use_rails_encrypted_credentials
  # limit the config keys we merge to credentials only
  aws_credential_keys = %i[access_key_id secret_access_key session_token]

  Aws.config.merge!(
    ::Rails.application.credentials[:aws].to_h.slice(*aws_credential_keys)
  )
end