First version, working only for S3, no tests.