boto3 错误无法获取实例的标签
boto3 error unable to get tags for instances
正在尝试使此代码正常工作。我想在我的 vpc 中获取实例的标签。我从这里得到代码 ()
import boto3
import boto3.ec2
s3 = boto3.resource('s3')
#for bucket in s3.buckets.all():
# print(bucket.name)
#
ec2 = boto3.resource('ec2', region_name='us-west-1')
vpc = ec2.Vpc("vpc-59d5d73d")
for i in vpc.instances.all():
for tag in i.tags:
if tag['Key'] == 'Name':
print tag['Value']
我使用 S3 代码只是为了确保我正确安装和配置了 boto,它确实 return 我帐户中的存储桶。
我的问题是当我 运行 我得到以下代码时:
python botoGetTags.py
Traceback (most recent call last):
File "botoGetTags.py", line 9, in <module>
ec2 = boto3.resource('ec2', region_name='us-west-2')
File "/Library/Python/2.7/site-packages/boto3/__init__.py", line 92, in resource
return _get_default_session().resource(*args, **kwargs)
File "/Library/Python/2.7/site-packages/boto3/session.py", line 389, in resource
aws_session_token=aws_session_token, config=config)
File "/Library/Python/2.7/site-packages/boto3/session.py", line 263, in client
aws_session_token=aws_session_token, config=config)
File "/Library/Python/2.7/site-packages/botocore/session.py", line 818, in create_client
client_config=config, api_version=api_version)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 62, in create_client
service_model = self._load_service_model(service_name, api_version)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 92, in _load_service_model
api_version=api_version)
File "/Library/Python/2.7/site-packages/botocore/loaders.py", line 123, in _wrapper
data = func(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/botocore/loaders.py", line 358, in load_service_model
return self.load_data(full_path)
File "/Library/Python/2.7/site-packages/botocore/loaders.py", line 123, in _wrapper
data = func(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/botocore/loaders.py", line 382, in load_data
raise DataNotFoundError(data_path=name)
我不知道在哪里可以找到此错误的修复程序。
你的代码对我来说工作得很好!
我建议你检查一下你是运行最新版本的boto:
sudo pip install boto3 --upgrade --ignore six
Successfully installed boto3-1.4.1 botocore-1.4.61 docutils-0.12 futures-3.0.5 jmespath-0.9.0 python-dateutil-2.5.3 s3transfer-0.1.7 six-1.10.0
正在尝试使此代码正常工作。我想在我的 vpc 中获取实例的标签。我从这里得到代码 (
import boto3
import boto3.ec2
s3 = boto3.resource('s3')
#for bucket in s3.buckets.all():
# print(bucket.name)
#
ec2 = boto3.resource('ec2', region_name='us-west-1')
vpc = ec2.Vpc("vpc-59d5d73d")
for i in vpc.instances.all():
for tag in i.tags:
if tag['Key'] == 'Name':
print tag['Value']
我使用 S3 代码只是为了确保我正确安装和配置了 boto,它确实 return 我帐户中的存储桶。
我的问题是当我 运行 我得到以下代码时:
python botoGetTags.py
Traceback (most recent call last):
File "botoGetTags.py", line 9, in <module>
ec2 = boto3.resource('ec2', region_name='us-west-2')
File "/Library/Python/2.7/site-packages/boto3/__init__.py", line 92, in resource
return _get_default_session().resource(*args, **kwargs)
File "/Library/Python/2.7/site-packages/boto3/session.py", line 389, in resource
aws_session_token=aws_session_token, config=config)
File "/Library/Python/2.7/site-packages/boto3/session.py", line 263, in client
aws_session_token=aws_session_token, config=config)
File "/Library/Python/2.7/site-packages/botocore/session.py", line 818, in create_client
client_config=config, api_version=api_version)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 62, in create_client
service_model = self._load_service_model(service_name, api_version)
File "/Library/Python/2.7/site-packages/botocore/client.py", line 92, in _load_service_model
api_version=api_version)
File "/Library/Python/2.7/site-packages/botocore/loaders.py", line 123, in _wrapper
data = func(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/botocore/loaders.py", line 358, in load_service_model
return self.load_data(full_path)
File "/Library/Python/2.7/site-packages/botocore/loaders.py", line 123, in _wrapper
data = func(self, *args, **kwargs)
File "/Library/Python/2.7/site-packages/botocore/loaders.py", line 382, in load_data
raise DataNotFoundError(data_path=name)
我不知道在哪里可以找到此错误的修复程序。
你的代码对我来说工作得很好!
我建议你检查一下你是运行最新版本的boto:
sudo pip install boto3 --upgrade --ignore six
Successfully installed boto3-1.4.1 botocore-1.4.61 docutils-0.12 futures-3.0.5 jmespath-0.9.0 python-dateutil-2.5.3 s3transfer-0.1.7 six-1.10.0