aws-cli icon indicating copy to clipboard operation
aws-cli copied to clipboard

IAM roles: 'NoneType' object has no attribute 'access_key'

Open jdub opened this issue 13 years ago • 9 comments

I have created an IAM role (using the VPC Full Access template, unedited, which includes ec2:DescribeInstances), launched an Ubuntu 12.04 LTS t1.micro with it attached, and installed aws-cli with easy_install...

ubuntu@ip-10-128-3-5:~$ curl http://169.254.169.254/latest/meta-data/iam/info && echo
{
  "Code" : "Success",
  "LastUpdated" : "2012-12-26T23:44:36Z",
  "InstanceProfileArn" : "arn:aws:iam::*REMOVED*:instance-profile/vpc-nat",
  "InstanceProfileId" : "*REMOVED*"
}
ubuntu@ip-10-128-3-5:~$ curl http://169.254.169.254/latest/meta-data/iam/security-credentials/vpc-nat && echo
{
  "Code" : "Success",
  "LastUpdated" : "2012-12-26T23:44:38Z",
  "Type" : "AWS-HMAC",
  "AccessKeyId" : "*REMOVED*",
  "SecretAccessKey" : "*REMOVED*",
  "Token" : "*REMOVED*",
  "Expiration" : "2012-12-27T06:07:57Z"
}
ubuntu@ip-10-128-3-5:~$ aws ec2 --region ap-southeast-2 describe-instances
'NoneType' object has no attribute 'access_key'

Per strace, two of the final things it tries to do is:

open("/etc/boto.cfg", O_RDONLY)         = -1 ENOENT (No such file or directory)
open("/home/ubuntu/.boto", O_RDONLY)    = -1 ENOENT (No such file or directory)

And the debug log:

ubuntu@ip-10-128-3-5:~$ aws --debug ec2 --region ap-southeast-2 describe-instances
2012-12-27 00:21:06,965 - botocore.base - DEBUG - Attempting to Load: aws/_services/ec2
2012-12-27 00:21:06,965 - botocore.base - DEBUG - Attempting to Load: aws
2012-12-27 00:21:06,965 - botocore.base - DEBUG - Attempting to Load: aws/_services
2012-12-27 00:21:06,966 - botocore.base - DEBUG - Found data file: /usr/local/lib/python2.7/dist-packages/botocore-0.4.1-py2.7.egg/botocore/data/aws/_services.json
2012-12-27 00:21:06,966 - botocore.base - DEBUG - Attempting to Load: aws/_services/ec2
2012-12-27 00:21:06,966 - botocore.base - DEBUG - Attempting to Load: aws/ec2
2012-12-27 00:21:06,996 - botocore.base - DEBUG - Found data file: /usr/local/lib/python2.7/dist-packages/botocore-0.4.1-py2.7.egg/botocore/data/aws/ec2.json
2012-12-27 00:21:07,064 - botocore.endpoint - DEBUG - {}
Traceback (most recent call last):
  File "/usr/local/lib/python2.7/dist-packages/awscli-0.4.4-py2.7.egg/awscli/clidriver.py", line 296, in call
    **params)
  File "/usr/local/lib/python2.7/dist-packages/botocore-0.4.1-py2.7.egg/botocore/operation.py", line 42, in call
    return endpoint.make_request(self, params)
  File "/usr/local/lib/python2.7/dist-packages/botocore-0.4.1-py2.7.egg/botocore/endpoint.py", line 78, in make_request
    headers={'User-Agent': user_agent})
  File "/usr/local/lib/python2.7/dist-packages/requests-0.14.2-py2.7.egg/requests/api.py", line 98, in post
    return request('post', url, data=data, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests-0.14.2-py2.7.egg/requests/safe_mode.py", line 39, in wrapped
    return function(method, url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests-0.14.2-py2.7.egg/requests/api.py", line 51, in request
    return session.request(method=method, url=url, **kwargs)
  File "/usr/local/lib/python2.7/dist-packages/requests-0.14.2-py2.7.egg/requests/sessions.py", line 228, in request
    args = dispatch_hook('args', args['hooks'], args)
  File "/usr/local/lib/python2.7/dist-packages/requests-0.14.2-py2.7.egg/requests/hooks.py", line 44, in dispatch_hook
    _hook_data = hook(hook_data)
  File "/usr/local/lib/python2.7/dist-packages/botocore-0.4.1-py2.7.egg/botocore/auth.py", line 77, in add_auth
    args['params']['AWSAccessKeyId'] = self.credentials.access_key
AttributeError: 'NoneType' object has no attribute 'access_key'

Note that if I supply AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables, it works as expected.

jdub avatar Dec 27 '12 00:12 jdub

Final detail:

ubuntu@ip-10-128-3-5:~$ aws --version
aws-cli/0.4.1 Python/2.7.3 Linux/3.2.0-32-virtual

jdub avatar Dec 27 '12 00:12 jdub

Thanks for the report. I'm firing up an ec2 instance with a role to try to reproduce this now.

garnaat avatar Dec 27 '12 15:12 garnaat

Fixed in https://github.com/boto/botocore/commit/4c0ff7c4a7b2c67d96981372748121fa24e61f68

garnaat avatar Dec 27 '12 16:12 garnaat

Any idea when botocore 0.4.1 is likely to hit pypi?

tingletech avatar Jan 03 '13 02:01 tingletech

Today. I'm decided to bundle a bunch of fixes and feature requests into a larger 0.5.0 release.

On Wed, Jan 2, 2013 at 6:49 PM, tingletech [email protected] wrote:

Any idea when botocore 0.4.1 is likely to hit pypi?

— Reply to this email directly or view it on GitHubhttps://github.com/aws/aws-cli/issues/12#issuecomment-11833569.

garnaat avatar Jan 03 '13 13:01 garnaat

This also occurs when there is no IAM group available. It is possible to not have this value set and still have instances on ec2 eg. when setting up and instance in the GUI the "IAM role:None" is selected causes no http://169.254.169.254/latest/meta-data/iam/ file to be created. This would also be a problem with machines not on AWS running aws-cli.

wget http://169.254.169.254/latest/meta-data/iam/ --2013-01-29 00:45:16-- http://169.254.169.254/latest/meta-data/iam/ Connecting to 169.254.169.254:80... connected. HTTP request sent, awaiting response... 404 Not Found 2013-01-29 00:45:16 ERROR 404: Not Found.

aws ec2 create-volume --region "ap-southeast-2" --availability-zone "ap-southeast-2a" --size "1" 'NoneType' object has no attribute 'access_key'

michft avatar Jan 29 '13 00:01 michft

The below result is what happens with a misconfigured. export AWS_CONFIG_FILE=/home/user/.aws and correct export EC2_SECRET_KEY= export EC2_ACCESS_KEY= The IAM role was a red herring.

$ aws ec2 create-volume --region ap-southeast-2 --availability-zone ap-southeast-2a --size 1 --debug

2013-02-15 10:54:40,990 - botocore.base - DEBUG - Attempting to Load: aws/_services/ec2 2013-02-15 10:54:40,990 - botocore.base - DEBUG - Attempting to Load: aws 2013-02-15 10:54:40,991 - botocore.base - DEBUG - Attempting to Load: aws/_services 2013-02-15 10:54:40,991 - botocore.base - DEBUG - Found data file: /usr/local/lib/python2.7/dist-packages/botocore-0.5.2-py2.7.egg/botocore/data/aws/_services.json 2013-02-15 10:54:40,991 - botocore.base - DEBUG - Attempting to Load: aws/_services/ec2 2013-02-15 10:54:40,992 - botocore.base - DEBUG - Attempting to Load: aws/ec2 2013-02-15 10:54:41,026 - botocore.base - DEBUG - Found data file: /usr/local/lib/python2.7/dist-packages/botocore-0.5.2-py2.7.egg/botocore/data/aws/ec2.json send: 'GET /latest/meta-data/iam/ HTTP/1.1\r\nHost: 169.254.169.254\r\nAccept-Encoding: gzip, deflate, compress\r\nAccept: /\r\nUser-Agent: python-requests/0.14.1 CPython/2.7.3 Linux/3.5.0-17-generic\r\n\r\n' reply: 'HTTP/1.0 404 Not Found\r\n' header: Content-Type: text/html header: Content-Length: 345 header: Connection: close header: Date: Fri, 15 Feb 2013 10:54:41 GMT header: Server: EC2ws 2013-02-15 10:54:41,106 - botocore.operation - DEBUG - {u'availability_zone': 'ap-southeast-2a', u'size': 1} 2013-02-15 10:54:41,107 - botocore.operation - DEBUG - {u'size': 1, u'availability_zone': 'ap-southeast-2a'} 2013-02-15 10:54:41,107 - botocore.parameters - DEBUG - label= 2013-02-15 10:54:41,107 - botocore.parameters - DEBUG - label= 2013-02-15 10:54:41,107 - botocore.endpoint - DEBUG - {u'AvailabilityZone': 'ap-southeast-2a', u'Size': '1'} 2013-02-15 10:54:41,107 - botocore.endpoint - DEBUG - SSL Verify: True Traceback (most recent call last): File "/usr/local/lib/python2.7/dist-packages/awscli-0.5.1-py2.7.egg/awscli/clidriver.py", line 292, in call *_params) File "/usr/local/lib/python2.7/dist-packages/botocore-0.5.2-py2.7.egg/botocore/operation.py", line 46, in call return endpoint.make_request(self, params) File "/usr/local/lib/python2.7/dist-packages/botocore-0.5.2-py2.7.egg/botocore/endpoint.py", line 91, in make_request verify=self.verify) File "/usr/local/lib/python2.7/dist-packages/requests-0.14.1-py2.7.egg/requests/api.py", line 98, in post return request('post', url, data=data, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-0.14.1-py2.7.egg/requests/safe_mode.py", line 39, in wrapped return function(method, url, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-0.14.1-py2.7.egg/requests/api.py", line 51, in request return session.request(method=method, url=url, *_kwargs) File "/usr/local/lib/python2.7/dist-packages/requests-0.14.1-py2.7.egg/requests/sessions.py", line 228, in request args = dispatch_hook('args', args['hooks'], args) File "/usr/local/lib/python2.7/dist-packages/requests-0.14.1-py2.7.egg/requests/hooks.py", line 44, in dispatch_hook _hook_data = hook(hook_data) File "/usr/local/lib/python2.7/dist-packages/botocore-0.5.2-py2.7.egg/botocore/auth.py", line 78, in add_auth args['params']['AWSAccessKeyId'] = self.credentials.access_key AttributeError: 'NoneType' object has no attribute 'access_key'

michft avatar Feb 15 '13 11:02 michft

Mentioned here, this can be caused by incorrect characters in your ~/.aws/credentials file.

davidfarinha avatar Jul 23 '20 10:07 davidfarinha

As commented earlier, this is fixed by setting correct values for:

AWS_SHARED_CREDENTIALS_FILE=~/.aws/credentials
AWS_CONFIG_FILE=~/.aws/config

If you're using Windows, and getting this error with Git for Windows:

AWS_SHARED_CREDENTIALS_FILE=$HOME\.aws\credentials
AWS_CONFIG_FILE=$HOME\.aws\config

KptnKMan avatar Jul 30 '20 09:07 KptnKMan