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

eCommerce trends: The future of grocery industry

eCommerce trends: The future of grocery industry

In 2016 nearly 25% of Americans ordered groceries online at least once. Over the next 2 years, that number has doubled and the total value of online sales of food and beverages is expected to exceed $25 billion for the first time. This is just a small fraction of the $1 trillion market and the

Apple Pay on the web

Apple Pay on the Web as of 2018

Ok, so you want to implement Apple Pay on your website? This article will uncover some pitfalls, tech-details, and gotchas of the implementation. There’s no end-to-end guide on how to implement it as there’s no such thing as a single right way to do this. The article may also help you to make a proper

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

Leave a Reply

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