将本地端点与boto2一起使用 [英] using local endpoint with boto2
本文介绍了将本地端点与boto2一起使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用boto2模拟AWS s3 api调用. 我使用 localstack 创建本地s3端点,并且可以通过boto3轻松使用它,如下所示,
I am trying to mock AWS s3 api calls using boto2. I create local s3 endpoint using localstack and can use this using boto3 easily as below,
import boto3
s3_client = boto3.client('s3', endpoint_url='http://localhost:4572')
bucket_name = 'my-bucket'
s3_client.create_bucket(Bucket=bucket_name)
但是我没有找到使用boto2做到这一点的方法.有什么方法可以使用〜/.boto或〜/.aws/config吗?
But I did not find way to do this using boto2. Is there any way preferably using ~/.boto or ~/.aws/config?
尝试向终端提供boto2,但失败.
Tried providing endpoint with boto2 but it failed.
import boto
boto.s3.S3RegionInfo(name='test-s3-region', endpoint='http://127.0.0.1:4572/')
s3 = boto.s3.connect_to_region('test-s3-region')
print s3.get_bucket('test-poc')
错误:
AttributeError: 'NoneType' object has no attribute 'get_bucket'
我希望将本地终端节点用于所有AWS服务以进行测试.
I am looking to use local endpoints for all AWS services for testing purpose.
推荐答案
这对我有用:
import boto
from boto.s3.connection import S3Connection
region = boto.s3.S3RegionInfo(name='test-s3-region', endpoint='http://127.0.0.1:4572/', connection_cls=S3Connection)
conn = region.connect()
print conn.get_bucket('test-poc')
您需要设置 connection_cls 属性默认情况下希望为NoneType .
这篇关于将本地端点与boto2一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文