VNarasimhaM
VNarasimhaM

Reputation: 1570

Amazon S3: how to set requests to use virtual host in ruby aws sdk

Currently, I am sending GET requests to S3 using aws-sdk ruby as follow:

#!/usr/bin/ruby
#
require 'aws-sdk'
s3 = Aws::S3::Resource.new(region: 'test',     endpoint:'http://10.0.23.45:8081')
my_bucket = s3.bucket('test.bucket-name')
my_bucket.objects.limit(50).each do |obj|
   puts "  #{obj.key} => #{obj.etag}"
end

But the request is trying to hit this url endpoint(virtual hosting):

http://test.bucket-name.10.0.23.45:8081

I would like to use path style addressing instead. This is what I want the request url endpoint to look like:

http://10.0.23.45:8081/test.bucket-name/

Any idea how to set path style addressing instead of virtual hosting address? Thanks.

Upvotes: 0

Views: 828

Answers (2)

VNarasimhaM
VNarasimhaM

Reputation: 1570

I found the answer for my own question after looking at the source code of ruby aws-sdk Source Code

 Aws.config[:s3] = { force_path_style: true }

Adding the above line forced to use path style addressing.

Upvotes: 3

Shaunak
Shaunak

Reputation: 18028

You need to set option :virtual_host to true according to documentation.

So in your case something like this should work:

s3.bucket('10.0.23.45:8081').object('test.bucket-name').public_url(virtual_host: true)
#=> "http://10.0.23.45:8081/test.bucket-name/"

Upvotes: 0

Related Questions