A Ruby on Rails plugin that integrates AWS services with your application using the latest version of AWS SDK For Ruby.
Add this gem to your Rails project's Gemfile:
gem 'aws-sdk-rails'
This gem also brings in the aws-sdk-core
, aws-sdk-sts
, and aws-sdk-ses
gems. If you want to use other services (such as S3), you will still need to add
them to your Gemfile:
gem 'aws-sdk-rails', '~> 2'
gem 'aws-sdk-s3', '~> 1'
You will have to ensure that you provide credentials for the SDK to use. See the latest AWS SDK for Ruby Docs for details.
If you're running your Rails application on Amazon EC2, keep in mind that the AWS SDK will automatically check Amazon EC2 instance metadata for credentials. Learn more: IAM Roles for Amazon EC2
The AWS SDK is automatically configured to use the built-in Rails logger for any
SDK log output. The logger is configured to use the :info
log level. You can
change the log level by setting :log_level
in the
Aws.config hash.
Aws.config.update(log_level: :debug)
If you are using Rails 5.2+ Encrypted Credentials, the credentials will be automatically loaded assuming the decrypted contents are provided as such:
# config/credentials.yml.enc
# viewable with: `rails credentials:edit`
aws:
access_key_id: YOUR_KEY_ID
secret_access_key: YOUR_ACCESS_KEY
This gem will automatically register SES as an ActionMailer delivery method. You simply need to configure Rails to use it in your environment configuration:
# for e.g.: config/environments/production.rb
config.action_mailer.delivery_method = :ses
If you need to provide different credentials for Action Mailer, you can call
client-creating actions manually. For example, you can create an initializer
config/initializers/aws.rb
with contents similar to the following:
require 'json'
# Assuming a file "path/to/aws_secrets.json" with contents like:
#
# { "AccessKeyId": "YOUR_KEY_ID", "SecretAccessKey": "YOUR_ACCESS_KEY" }
#
# Remember to exclude "path/to/aws_secrets.json" from version control, e.g. by
# adding it to .gitignore
secrets = JSON.load(File.read('path/to/aws_secrets.json'))
creds = Aws::Credentials.new(secrets['AccessKeyId'], secrets['SecretAccessKey'])
Aws::Rails.add_action_mailer_delivery_method(
:ses,
credentials: creds,
region: 'us-east-1'
)