Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to mock Amazon S3 in an integration test

I'm trying to get an "walking skeleton" of my app up that will use S3 for persistence. I would like to use a fake S3 service so each developer's desktop can read/write at will.

I thought mocks3 would be perfect, as I could get a jetty server up in my jUnit tests. The problem is that mocks3 doesn't allow any writes. Not even to set it up as far as I can tell.

So how do others do this?

like image 933
Michael Deardeuff Avatar asked Jul 07 '11 19:07

Michael Deardeuff


People also ask

How do I mock amazons3 client?

start(); AmazonS3Client client = new AmazonS3Client(new AnonymousAWSCredentials()); // use local API mock, not the AWS one client. setEndpoint("http://127.0.0.1:8001"); client. createBucket("testbucket"); client. putObject("testbucket", "file/name", "contents");

How do I check my S3 service?

You can use the Amazon Web Services Command Line Interface (AWS CLI) to test your connection to the system and to verify that you can read and write objects to the system.

What is S3 integration?

When you enable the Amazon S3 integration, raw Segment data gets copied into your Amazon S3 bucket automatically. The data is stored as line-separated JSON objects and follows the Segment Spec, which was designed to be clean and easy to understand. Each object contains the data from a single API call made to Segment.


1 Answers

There is also an Findify s3mock tool written exactly for this purpose. It mocks the essential parts of AWS S3 API on top of local filesystem:

import io.findify.s3mock.S3Mock  S3Mock api = S3Mock.create(8001, "/tmp/s3"); api.start();  AmazonS3Client client = new AmazonS3Client(new AnonymousAWSCredentials()); // use local API mock, not the AWS one client.setEndpoint("http://127.0.0.1:8001"); client.createBucket("testbucket"); client.putObject("testbucket", "file/name", "contents"); 

It's also easily embeddable and configuration-less.

like image 115
shutty Avatar answered Sep 26 '22 06:09

shutty