AWS services or capabilities described in AWS Documentation may vary by region/location. Click Getting Started with Amazon AWS to see specific differences applicable to the China (Beijing) Region.

AWS SDK for Ruby Rails Plugin

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 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', '~> 3'
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, the AWS SDK will automatically check Amazon EC2 instance metadata for credentials. Learn more: IAM Roles for Amazon EC2


AWS SDK uses the Rails logger

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)

Rails 5.2+ Encrypted Credentials

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`
  access_key_id: YOUR_KEY_ID
  secret_access_key: YOUR_ACCESS_KEY

Amazon Simple Email Service (SES) as an ActionMailer Delivery Method

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

Other Usage

Manually setting Action Mailer credentials

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('path/to/aws_secrets.json'))
creds =['AccessKeyId'], secrets['SecretAccessKey'])

  credentials: creds,
  region: 'us-east-1'

Using ARNs with SES

This gem uses Aws::SES::Client#send_raw_email to send emails. This operation allows you to specify a cross-account identity for the email's Source, From, and Return-Path. To set these ARNs, use any of the following headers on your Mail::Message object returned by your Mailer class:





# in your Rails controller
message = MyMailer.send_email(options)
message['X-SES-FROM-ARN'] = 'arn:aws:ses:us-west-2:012345678910:identity/'