Boto
来源:互联网 发布:淘宝商品上下架 编辑:程序博客网 时间:2024/05/14 01:44
CREATING A CONNECTION
This creates a connection so that you can interact with the server.
import boto
import boto.s3.connection
access_key = 'put your access key here!'
secret_key = 'put your secret key here!'
conn = boto.connect_s3(
aws_access_key_id = access_key,
aws_secret_access_key = secret_key,
host = 'objects.dreamhost.com',
#is_secure=False, # uncommmnt if you are not using ssl
calling_format = boto.s3.connection.OrdinaryCallingFormat(),
)
LISTING OWNED BUCKETS
This gets a list of Buckets that you own. This also prints out the bucket name and creation date of each bucket.
for bucket in conn.get_all_buckets():
print "{name}\t{created}".format(
name = bucket.name,
created = bucket.creation_date,
)
The output will look something like this:
mahbuckat1 2011-04-21T18:05:39.000Z
mahbuckat2 2011-04-21T18:05:48.000Z
mahbuckat3 2011-04-21T18:07:18.000Z
CREATING A BUCKET
This creates a new bucket called my-new-bucket
bucket = conn.create_bucket('my-new-bucket')
LISTING A BUCKET’S CONTENT
This gets a list of objects in the bucket. This also prints out each object’s name, the file size, and last modified date.
for key in bucket.list():
print "{name}\t{size}\t{modified}".format(
name = key.name,
size = key.size,
modified = key.last_modified,
)
The output will look something like this:
myphoto1.jpg 251262 2011-08-08T21:35:48.000Z
myphoto2.jpg 262518 2011-08-08T21:38:01.000Z
DELETING A BUCKET
Note The Bucket must be empty! Otherwise it won’t work!
conn.delete_bucket(bucket.name)
FORCED DELETE FOR NON-EMPTY BUCKETS
Attention not available in python
CREATING AN OBJECT
This creates a file hello.txt with the string "Hello World!"
key = bucket.new_key('hello.txt')
key.set_contents_from_string('Hello World!')
CHANGE AN OBJECT’S ACL
This makes the object hello.txt to be publicly readable, and secret_plans.txt to be private.
hello_key = bucket.get_key('hello.txt')
hello_key.set_canned_acl('public-read')
plans_key = bucket.get_key('secret_plans.txt')
plans_key.set_canned_acl('private')
DOWNLOAD AN OBJECT (TO A FILE)
This downloads the object perl_poetry.pdf and saves it in /home/larry/documents/
key = bucket.get_key('perl_poetry.pdf')
key.get_contents_to_filename('/home/larry/documents/perl_poetry.pdf')
DELETE AN OBJECT
This deletes the object goodbye.txt
bucket.delete_key('goodbye.txt')
GENERATE OBJECT DOWNLOAD URLS (SIGNED AND UNSIGNED)
This generates an unsigned download URL for hello.txt. This works because we made hello.txt public by setting the ACL above. This then generates a signed download URL for secret_plans.txt that will work for 1 hour. Signed download URLs will work for the time period even if the object is private (when the time period is up, the URL will stop working).
hello_key = bucket.get_key('hello.txt')
hello_url = hello_key.generate_url(0, query_auth=False, force_http=True)
print hello_url
plans_key = bucket.get_key('secret_plans.txt')
plans_url = plans_key.generate_url(3600, query_auth=True, force_http=True)
print plans_url
The output of this will look something like:
http://objects.dreamhost.com/my-bucket-name/hello.txt
http://objects.dreamhost.com/my-bucket-name/secret_plans.txt?Signature=XXXXXXXXXXXXXXXXXXXXXXXXXXX&E...
0 0
- Boto
- boto for Amazon
- Boto Config File
- Python 安装boto boto3
- AWS kinesis use boto, boto use aws_security_token or aws_session_token
- Boto - python lib for AWS
- python boto AWS SQS connection
- Guide to boto -- MWS package
- 使用BOTO进行S3各种操作
- An Example Using boto Amazon MWS Package
- 使用Python 和Boto 库将文件备份到AmazonS3
- 基于boto的几个Elastic IP的用法
- 【Amazon EC2 Python API系列】boto的介绍和安装
- Boto:利用Python将自动化机制引入AWS服务
- AWS EC2上传文件到S3(python boto)
- scrapy [boto] ERROR: Caught exception reading instance data URLError: <urlopen error [Errno 10051] >
- IDCFオブジェクトストレージをs3cmdやbotoで使う
- yii_yii框架的中文api地址
- 阿里巴巴2013年实习生笔试题A
- Spring-AOP-Exception
- 谁戴黑帽子
- Construct Binary Tree from Inorder and Postorder Traversal
- Boto
- 【贪心算法】独木舟上的旅行
- java 异常总结 Java核心技术读书笔记
- C++中的delete——读书笔记
- 关于常量传播(如何修改const常量的值)
- Shopaholic
- SVN操作
- 国内从事CV相关的企业
- 虔诚的学习者 阿里巴巴2013年实习生笔试题B