簡體   English   中英

boto3錯誤無法獲取實例的標簽

[英]boto3 error unable to get tags for instances

試圖使此代碼正常工作。 我想在我的vpc中獲取實例的標簽。 我從這里得到了代碼( 使用Boto 3顯示EC2實例名稱

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,並且確實確實返回了我帳戶中的存儲桶。

我的問題是,當我運行以下代碼時,我得到:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM