Tag: boto

我如何安装博托?

所以我可以在我的Python脚本中使用它?

用Boto3打开S3对象作为string

我知道,与博托2可以打开一个S3对象作为string: get_contents_as_string() http://boto.readthedocs.org/en/latest/ref/file.html?highlight=contents%20string#boto.file.key.Key.get_contents_as_string 在boto3中有一个等价的函数吗?

AWS boto和boto3有什么区别?

我是使用Python的AWS的新手,我正在尝试学习boto API,但是我注意到Python有两个主要的版本/软件包。 这将是博托,和boto3。 我一直无法find这些软件包的主要优点/缺点或差异的文章。

Boto3,Python和如何处理错误

我刚刚拿起python作为我的前往脚本语言,我正试图找出如何做适当的error handling与boto3。 我正在尝试创build一个IAM用户: def create_user(username, iam_conn): try: user = iam_conn.create_user(UserName=username) return user except Exception as e: return e 当调用create_user成功时,我得到一个整洁的对象,其中包含API调用的http状态代码和新创build的用户的数据。 例: {'ResponseMetadata': {'HTTPStatusCode': 200, 'RequestId': 'omitted' }, u'User': {u'Arn': 'arn:aws:iam::omitted:user/omitted', u'CreateDate': datetime.datetime(2015, 10, 11, 17, 13, 5, 882000, tzinfo=tzutc()), u'Path': '/', u'UserId': 'omitted', u'UserName': 'omitted' } } 这很好。 但是,当这失败(如用户已经存在),我只是得到一个botocore.exceptions.ClientErrortypes的对象只有文本告诉我什么地方出错了。 例如:ClientError('调用CreateUser操作时发生错误(EntityAlreadyExists):名称被忽略的用户已经存在',) 这个(AFAIK)使得error handling非常困难,因为我不能只打开生成的http状态代码(根据IAM的AWS API文档,用户已经存在了409个)。 这让我觉得我一定是在做错事。 最佳的方式是让boto3永远不会抛出exception,但juts总是返回一个反映API调用行为的对象。 任何人都可以在这个问题上启发我,或指出我在正确的方向吗? […]

如何使用boto3将S3对象保存到文件中

我试图用新的boto3客户端来做一个“hello world”。 我使用的用例很简单:从S3获取对象并将其保存到文件中。 在博托2.XI会这样做: import boto key = boto.connect_s3().get_bucket('foo').get_key('foo') key.get_contents_to_filename('/tmp/foo') 在博托3。 我无法find一个干净的方式来做同样的事情,所以我手动迭代“stream”对象: import boto3 key = boto3.resource('s3').Object('fooo', 'docker/my-image.tar.gz').get() with open('/tmp/my-image.tar.gz', 'w') as f: chunk = key['Body'].read(1024*8) while chunk: f.write(chunk) chunk = key['Body'].read(1024*8) 要么 import boto3 key = boto3.resource('s3').Object('fooo', 'docker/my-image.tar.gz').get() with open('/tmp/my-image.tar.gz', 'w') as f: for chunk in iter(lambda: key['Body'].read(4096), b''): f.write(chunk) 它工作正常。 我想知道是否有任何“本地”boto3function,将执行相同的任务?