Reputation: 61
I am using the latest version of the refile gem to upload images to AWS and it's working fine. when I try to test my app with rspec i get this error:
/aws-sdk-core/plugins/regional_endpoint.rb:34:in `after_initialize': missing region; use :region option or export region name to ENV['AWS_REGION'] (Aws::Errors::MissingRegionError)
Gemfile:
gem "refile", require: "refile/rails"
gem "refile-mini_magick"
gem "refile-s3"
refile.rb
require 'refile/simple_form'
require "refile/s3"
aws = {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: ENV['AWS_REGION'],
bucket: ENV['AWS_BUCKET']
}
Refile.cache = Refile::S3.new(prefix: "cache", **aws)
Refile.store = Refile::S3.new(prefix: "store", **aws)
I tried setting a new initializer aws.rb:
require 'aws-sdk'
Aws.config.update({ region: 'us-west-2', credentials: Aws::Credentials.new('akid', 'secret') })
but it did not work.
10x for your help!
Upvotes: 1
Views: 1496
Reputation: 61
found the answer: just add to your initializers/refile.rb:
require "refile/s3"
require 'refile/simple_form'
if Rails.env.production?
aws = {
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY'],
region: ENV['AWS_REGION'],
bucket: ENV['AWS_BUCKET']
}
Refile.cache = Refile::S3.new(prefix: "cache", **aws)
Refile.store = Refile::S3.new(prefix: "store", **aws)
end
Upvotes: 1
Reputation: 194
It looks like your code is looking for the AWS_REGION value as an environment variable. Have you verified that the value for AWS_REGION is being set in your environment before running your tests? You can see if it's set in bash by doing the following:
env | grep AWS_REGION
If it's not set, then just need to set the variable like so (again in bash):
export AWS_REGION="us-west-2"
Upvotes: 0