Blog

Configuring Heroku, AWS S3 and Paperclip to work with a bucket outside of the USA

A functionality of adding images to new or existing products is a must for any eCommerce application. This feature is also included in Spree and with a quick configuration works very well within the USA.

Lately, we have been configuring a new Spree application (that comes with a Paperclip already included), running on Heroku, to work with an Amazon S3 bucket. This time, the AWS resource was located in Ireland, Europe. As usual, we have followed instructions available on the Heroku devcenter. After adding Amazon Web Service Security Credentials and the bucket name as environment variables to the Heroku config and referring to these variables from Paperclip config we were already able to upload and remove the images to the S3. However, the images in our views were still missing. Instead, we were seeing the following XML message from the S3:

The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint.

From the message description, we have deducted that the image links should refer to the proper Amazon region. The issues were the image links generated by the Paperclip. The link in the following form was not directing us to the EU resource:

s3.amazonaws.com/bucket_name/...

Few nodes below the error message the proper endpoint was specified and indeed changing the address in a web browser to the specified endpoint lead us to the resource uploaded via Paperclip to the S3.

bucket_name.s3.amazonaws.com/...

We started looking into the Paperclip documentation and searching for similar issues via google. We have found a suggestion of interpolating the link and moving the bucket_name into the subdomain, but this approach seemed really rough. After a little more research we have discovered the bucket is actually available via a different link as well.

s3-eu-west-1.amazonaws.com/bucket_name/...

That’s more like it! Using this point of access we wouldn’t have to mess with the link structure generated by the Paperclip, but only change the domain that we are refering to. In the end simply expanding the production config with two additional lines did the trick.

config.paperclip_defaults = {
:storage => :s3,
:s3_credentials => {
:bucket => ENV['S3_BUCKET_NAME'],
:access_key_id => ENV['AWS_ACCESS_KEY_ID'],
:secret_access_key => ENV['AWS_SECRET_ACCESS_KEY']
},

:s3_host_name => "s3-eu-west-1.amazonaws.com", # Added entry
:url => ":s3_host_name"                        # Added entry
}

This is how to make Heroku, Rails and Paperclip gem work with an Amazon S3 bucket located in a region different than the US.

No comments
Adam PacaConfiguring Heroku, AWS S3 and Paperclip to work with a bucket outside of the USA

Related Posts

Open Commerce Conf 2016 & multiple Spree success stories

The first Spree dedicated event since Spree Conf 2014 took place on June 28-29th in New York. Organized by Spark Solutions team, it was a 2 day event that connected developers and business people interested in eCommerce open source solutions. It was packed with real life know-how, discussion and Spree Commerce success stories. Followed by a

OpenCommerce Conf

Join us in New York City on June 28-29th for OpenCommerce Conf 2016

Join us in New York City on June 28-29th for OpenCommerce Conf 2016: http://opencommerceconf.org/ It’s a 2 day event on E-Commerce with great speakers, Spree success stories, discussion panels for both developers and business people and of course drinks in the afternoon. There are thousands of Spree store owners and developers all over the world

Campus Warsaw

DevHeroes – meetup for Ruby and JavaScript developers organized by Spark Solutions

On April 12th, 2016 the historic, first DevHeroes meetup gathered a crowd of software engineers who decided to combine their superpowers for that one special evening. It was hosted by Campus Warsaw, one of Google’s hubs for startup communities placed in some of the most innovative cities like London, Tel Aviv, Madrid, Sao Paolo and Seoul.

Leave a Reply

Your email address will not be published. Required fields are marked *