scireum / s3ninja

S3 ninja emulates the Amazon S3 API for developement and test purposes
MIT License
494 stars 91 forks source link

Sample on using your tool #178

Closed wifilocator closed 3 years ago

wifilocator commented 3 years ago

Hi, Thanks for your help earlier, would you be able to provide a code snippet or how can I update some existing code to use your emulator, as I have some existing code which sends up files to an Amazon S3 bucket, but I don't see how I retarget this towards your S3 ninja docker image? - and think that would be great info to have in your readme. Thanks

jakobvogel commented 3 years ago

Hello @wifilocator 👋 This depends very much on the library/tool in use. For the official AWS Java library, you can see samples in our test cases, for instance here. In a Docker environment, make sure to use the correct port, as listed in the output of docker ps. Still, examples in the README would be useful, agreed. We will see to add them the next time we work on the tool. Thanks for pointing this out. Cheers!

wifilocator commented 3 years ago

Thank you for your unit test example - Can you advise why there is a need for

    newClient.setS3ClientOptions(S3ClientOptions.builder().setPathStyleAccess(true).build())

as added endpoint, and that works, so wonder why this is needed or needed for others ?

jakobvogel commented 3 years ago

Path style access means that the library generates URLs like http://<server>/<bucket>/<key> when talking to S3 Ninja. This is the old standard. By default, subdomains are used these days, leading to URLs like http://<bucket>.<server>/<key>. (Sorry if I state the obvious here. As this issue may serve as future reference for others as well, I have decided to still put it here. 😉)

In theory, S3 Ninja should support both access styles; or at least, it is somewhat prepared for subdomain-style access. That is, if the request reaches the server at all. The problem is that network routing needs to work properly for the requests to reach S3 Ninja, including the requested full host name (in order to extract the bucket name). Depending on the setup of your system, you may need to edit your hosts file, for instance. While this can be done of course, we generally recommend (and use) path-style access. It is just the simpler solution, considering that S3 Ninja is a development tool and you probably want to invest your time into something more fruitful than its setup… 😅 However, if subdomain-style access works for you right out of the box: Great, even better! 😊