Permalink
Browse files

Fix bug in _populate_keys_from_metadata_server when running on ec2 in…

…stance w/o an instance profile associated with it.
  • Loading branch information...
1 parent e20d3ea commit 924095d61a58535a81f8bc39c8fbde9e07985b2d @garnaat garnaat committed Jun 13, 2012
Showing with 9 additions and 10 deletions.
  1. +9 −10 boto/provider.py
View
@@ -207,17 +207,16 @@ def _populate_keys_from_metadata_server(self):
# dependency.
from boto.utils import get_instance_metadata
timeout = config.getfloat('Boto', 'metadata_service_timeout', 1.0)
- credentials = get_instance_metadata(timeout=timeout, num_retries=1)
- if credentials is None:
- return
+ metadata = get_instance_metadata(timeout=timeout, num_retries=1)
# I'm assuming there's only one role on the instance profile.
- security = credentials['iam']['security-credentials'].values()[0]
- if self.access_key is None:
- self.access_key = security['AccessKeyId']
- if self.secret_key is None:
- self.secret_key = security['SecretAccessKey']
- if self.security_token is None:
- self.security_token = security['Token']
+ if metadata and 'iam' in metadata:
+ security = credentials['iam']['security-credentials'].values()[0]
+ if self.access_key is None:
+ self.access_key = security['AccessKeyId']
+ if self.secret_key is None:
+ self.secret_key = security['SecretAccessKey']
+ if self.security_token is None:
+ self.security_token = security['Token']
def configure_headers(self):
header_info_map = self.HeaderInfoMap[self.name]

0 comments on commit 924095d

Please sign in to comment.