This post is incomplete and more of a note for oneself – be advices.
Here’s the way I’ve been trying to mock S3 for local testing, using Ruby FakeS3 app: https://github.com/jubos/fake-s3
In order to make S3 endpoints point to localhost I had to create custom regions override XML and debug AWS Java SDK to figure out it’s format.
I also have to pass path of that file as system property in order for AWS Java SDK to use it:
-Dcom.amazonaws.regions.RegionUtils.fileOverride=/Users/user/.aws-regions-override.xml -Dcom.amazonaws.sdk.disableCertChecking=true -Dcom.amazonaws.regions.RegionUtils.disableRemote=true
I could not find a way to disable SSL (switch from HTTPS to HTTP) in Amason AWS SDK without modifying the code of apps (which I can’t do – otherwise I’d just set endpoint manually), thus I ran FakeS3 configured with some random certificates, and pass disableCertChecking property. Also RegionUtils.disableRemote property is included to reduce number of helper calls to actual AWS.
Still, I did not find any possibility to make AWS SDK use path style access – thus bucket name is prepended to my localhost:9000 URL configured in .aws-regions-override.xml file, and thus I still had to add some entries to /etc/hosts to make it point to localhost. But at least I did not break any real AWS URLs with that.
UPD: Also, in order for endpoint URI to change one has to call setRegion in code at least once. This works for Spring wrapper over AWS S3 SDK, but may not work for custom code, that instantiates S3 client without setting region.
The content of .aws-regions-override.xml is this (the “whatever” tag can have any name):
<whatever> <Region> <Name>localhost</Name> <Domain>localhost</Domain> <Endpoint> <ServiceName>s3</ServiceName> <Hostname>localhost:9000</Hostname> <Http>true</Http> <Https>true</Https> </Endpoint> </Region> <Region> <Name>us-east-1</Name> <Domain>localhost</Domain> <Endpoint> <ServiceName>s3</ServiceName> <Hostname>localhost:9000</Hostname> <Http>true</Http> <Https>true</Https> </Endpoint> </Region> ... </whatever>