Feb 14, 2017 AWS 中文版
Fake S3 is a handy and lightweight development tool written in Ruby. It allows us to simulate a S3 service and test APIs of S3 in your development environment. This post is going to walk through how to use Fake S3 on macOS.
Some one already made a nice Dockerfile for Fake S3, and I’m going to use it in this tutorial. So, make sure you have Docker installed. But if you still want to install Fake S3 on your machine directly, you can do this:
gem install fakes3
It’s really easy to start a Fake S3 container:
# Run Fake S3 as a standalone service, and open the port 4569
docker run -d \
-p 4569:4569 \
--name s3 \
lphoward/fake-s3
To get your application to work with Fake S3, all you need to do is change the endpoint when you initialize a client object. Here are two examples using Python and PHP:
# Python example
from boto3 import client
s3_client = client(
service_name='s3',
endpoint_url='http://your-fake-s3-ip:4569',
region_name='',
aws_access_key_id='',
aws_secret_access_key=''
)
# PHP example
use Aws\S3\S3Client;
use Aws\Exception\S3Exception;
$fake_s3_settings = [
'version' => 'latest',
'region' => '',
'endpoint' => 'http://your-fake-s3-ip:4569',
'credentials' => [
'key' => '',
'secret' => ''
]
];
$s3_client = new S3Client($fake_s3_settings);
If everything goes right, you can find all your uploaded files under the /fakes3_root folder in the container. And the path of your file looks like this: /fakes3_root/bucket_name/path/to/your/file.
If you have any suggestions, questions or even find some typos, feel free to contact me. Thank you! :)
zeckli.devforgalaxy@gmail.com © 2015-2019 zeckli, thanks to Jekyll and GitHub.