fake-s3 icon indicating copy to clipboard operation
fake-s3 copied to clipboard

Creating buckets without adding bucket name as subdomain to /etc/hosts

Open sonjapeterson opened this issue 8 years ago • 1 comments

Hi there. Thanks for writing a very helpful library! I started using fake-s3 for testing an app where we are using AWS Ruby V2 SDK, and I was having some trouble creating a bucket. I noticed that I was able to create buckets that had underscores or capital letters, but not buckets without them. Digging in further I realized that the SDK was making slightly different requests depending on the name of the bucket.

When the bucket had an underscore or capital letter, the request was: PUT http://localhost:4567/my_bucket and worked just fine.

But without those, it used a subdomain and did not work: PUT http://my-bucket.localhost:4567

I realized that this was because underscores aren't allowed in subdomains. The S3 API/SDKs seem to make the request to create a bucket differently depending on whether they are able to use the bucket name as a subdomain. When they can't, they send it as a parameter instead.

I have a failing test case for this written here: https://github.com/sonjapeterson/fake-s3/commit/26330d7ef937f4fa037d5fc4c547acff2957045d

I could get it to work by adding the following to /etc/hosts: 127.0.0.1 localhost my-bucket.localhost

But I'd rather not have to do that for every bucket I create.

Is there a way around this without having to edit /etc/hosts (or, I suppose I could set up wildcard subdomains for localhost with something like dnsmasq)? If not, I'd be happy to open a PR and add some documentation around this to help other people out.

sonjapeterson avatar Sep 23 '16 21:09 sonjapeterson

@sonjapeterson I ran into this same problem and adding a leading / to the bucket name seems to be a workaround.

e.g. instead of my-bucket use /my-bucket.

Although there should be documentation on this

ShaneOH avatar Sep 27 '16 19:09 ShaneOH