[英]using local endpoint with boto2
我正在尝试使用boto2模拟AWS s3 api调用。 我使用localstack创建了本地s3终结点,并可以通过boto3轻松使用它,如下所示,
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吗?
尝试向终端提供boto2,但失败。
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服务使用本地终端节点进行测试。
这对我有用:
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 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.