Reputation: 1687
Trying to get this code working. I want to get the tags of the instances in my vpc. I got the code from here (Displaying EC2 Instance name using Boto 3)
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']
I used the S3 code just to make sure that I installed and configured boto correctly and it did indeed return the buckets in my account.
My problem is when I run the code below I get:
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)
I'm just lost on where to look for the fix to this error.
Upvotes: 0
Views: 1037
Reputation: 269340
Your code worked fine for me!
I suggest you check that you are running the latest version of 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
Upvotes: 1