s3proxy

網址:https://github.com/gaul/s3proxy
可以在本機端測試 S3,而不需要去開 S3 bucket 跟弄 AWS credential ,s3proxy 提供了跟 S3 一樣的 API 介面。

boto3 可以用,用法參考這邊:https://github.com/gaul/s3proxy/wiki/Client-compatibility-list

# Python3 + boto3 example
session = boto3.session.Session(aws_access_key_id='identity',
                                aws_secret_access_key='credential')
config = boto3.session.Config(s3={'addressing_style': 'path'})
# low level S3 client
client = session.client('s3', endpoint_url='http://localhost:60080',
                        config=config)
# S3 resource object
resource = session.resource('s3', endpoint_url='http://localhost:60080',
                            config=config)

用 docker 快速啟動

mkdir -p /tmp/data
docker run --publish 60080:80 -v /tmp/data:/data --env S3PROXY_AUTHORIZATION=none andrewgaul/s3proxy

django-storage 的話,應該是要改設定裡的 AWS_S3_ENDPOINT_URL

boto3 create_instances/run_instances

create_instances 是 boto3.resource(‘ec2’) 提供的,而 run_instances 是 boto3.client(‘ec2’) 提供的。

  • client(‘ec2’): A low-level client representing Amazon Elastic Compute Cloud (EC2)
  • resource(‘ec2’): A resource representing Amazon Elastic Compute Cloud (EC2)

主要不同點:Resources represent an object-oriented interface to Amazon Web Services (AWS). They provide a higher-level abstraction than the raw, low-level calls made by service clients. To use resources, you invoke the resource() method of a Session and pass in a service name。

也就是說實際上 ServiceResource 會去使用 client,簡單的說 ServiceResource 是一個 client wrapper (這可以從 boto3/session.py 看到)。

友情小提示:在閱讀程式碼時,用 function name 去找,會發現都找不到,實際上 boto3 library 會將 function call/parameters 轉換為 AWS API  呼叫送出去。