AJP
AJP

Reputation: 28453

accessing non standard s3 bucket

Using the aws-s3 gem, I can successfully perform transaction with a standard s3 bucket but one made in Ireland (s3-eu-west-1) gives the error The bucket you are attempting to access must be addressed using the specified endpoint. Please send all future requests to this endpoint. After 2 hours of searching this still means nothing to me, is there a way to get round this problem.

This simple tutorial works fine for standard s3 bucket but not for Ireland.

This person's experiences seem to suggest it's not possible.

Upvotes: 1

Views: 873

Answers (1)

AJP
AJP

Reputation: 28453

Ok I've just found the answer here.

require 'aws/s3'
AWS::S3::Base.establish_connection!(
  :access_key_id     => ACCESS_KEY_ID,
  :secret_access_key => SECRET_ACCESS_KEY
)
AWS::S3::DEFAULT_HOST.replace('s3-eu-west-1.amazonaws.com')  # <= the crucial hacky line
AWS::S3::S3Object.store(
  file_name,
  temp_file,
  bucket,
  :content_type => mime_type
)

Edit

Much better option is to use the aws-sdk gem whose API seems a lot nicer, e.g.:

require 'aws-sdk'
s3 = AWS::S3.new(
    :access_key_id => ACCESS_KEY_ID,
    :secret_access_key => SECRET_ACCESS_KEY,
    :s3_endpoint => 's3-eu-west-1.amazonaws.com'
)
bucket = s3.buckets[bucket_name]
bucket.objects.create(
  file_name,
  temp_file,
  :content_type => mime_type
)

Upvotes: 6

Related Questions