I'm trying to create an image uploader using paperclip, the aws-sdk gem and Amazon S3. I get this error:
Aws::Errors::MissingRegionError in ProjectsController#create.
Missing region; use :region option or export region name to ENV['AWS_REGION']. using Oregon region.
projects_controller.rb
def create
@project = current_user.projects.new(project_params)
@project.save
respond_with(@project)
end
application.rb file
config.paperclip_defaults = {
storage: :s3,
s3_host_name: "s3-us-west-2.amazonaws.com",
s3_credentials: {
bucket: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
}
According to the S3 documentation I understand I need to change to ENV['AWS_REGION']
config.paperclip_defaults = {
storage: :s3,
region: "ENV['AWS_REGION"],
s3_credentials: {
bucket: ENV['AWS_BUCKET'],
access_key_id: ENV['AWS_ACCESS_KEY_ID'],
secret_access_key: ENV['AWS_SECRET_ACCESS_KEY']
}
}
and add region to my .env file
export AWS_BUCKET=realv1
export AWS_ACCESS_KEY_ID=<MY_ACCESS_KEY_ID_HERE>
export AWS_SECRET_ACCESS_KEY=<MY_ACCESS_KEY_HERE>
export AWS_REGION="'us-west-2'
I rebooted the server and retested but still get the same errors.
update
update:
in rails console
2.0.0p247 :001 > ENV["AWS_REGION"]
=> "us-west-2" 2.0.0p247 :002 >
AWS_REGION
are messed up. – Aleksei Matiushkin