Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Amazon S3 standalone stub server

I seem to recall reading about an Amazon S3-compatible test server that you could run on your own server for unit tests or whatever. However, I've just exhausted my patience looking for this with both Google and AWS. Does such a thing exist? If not, I think I'll write one.

Note: I'm asking about Amazon S3 (the storage system) rather than Amazon EC2 (cloud computing).

like image 626
Greg Hewgill Avatar asked Sep 18 '08 10:09

Greg Hewgill


2 Answers

Are you thinking of Park Place?

FYI, its old home page is offline now.

like image 119
Luke Bennett Avatar answered Sep 19 '22 09:09

Luke Bennett


I think moto (https://github.com/spulec/moto) is the perfect tool for your unittests. Moto mocks all accesses to S3, SQS, etc. and can be used in any programming language using their web server.

It is trivial to setup, lightweight and fast.

From moto's README:

Imagine you have the following code that you want to test:

import boto
from boto.s3.key import Key

class MyModel(object):
    def __init__(self, name, value):
        self.name = name
        self.value = value

    def save(self):
        conn = boto.connect_s3()
        bucket = conn.get_bucket('mybucket')
        k = Key(bucket)
        k.key = self.name
        k.set_contents_from_string(self.value)

Take a minute to think how you would have tested that in the past. Now see how you could test it with Moto:

import boto
from moto import mock_s3
from mymodule import MyModel

@mock_s3
def test_my_model_save():
    model_instance = MyModel('steve', 'is awesome')
    model_instance.save()

    conn = boto.connect_s3()
    assert conn.get_bucket('mybucket').get_key('steve') == 'is awesome'
like image 21
andres.riancho Avatar answered Sep 20 '22 09:09

andres.riancho