libcloud-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [libcloud] pythonmobile opened a new issue #1601: EC2 iam role not working for list_nodes()
Date Wed, 08 Sep 2021 20:59:14 GMT

pythonmobile opened a new issue #1601:
URL: https://github.com/apache/libcloud/issues/1601


   ## Summary
   
   I am trying to list nodes from an EC2 instance by getting temporary credentials for building
a driver. I could use help in making this work.
   
   ## Detailed Information
   import os
   import logging
   import pathlib
   import requests
   import configparser
   from libcloud.compute.types import Provider
   from libcloud.compute.providers import get_driver
   
   IAM_METADATA_URL = "http://169.254.169.254/latest/meta-data/iam/security-credentials"
   region = "us-east-1"
   role = "MyProject-EC2-Manage-Role"
   
   url = "/".join((IAM_METADATA_URL, role))
   print("URL:", url)
   response = requests.get(url)
   response.raise_for_status()
   resp_json = response.json()
   aws_ak = resp_json.get("AccessKeyId")
   aws_sk = resp_json.get("SecretAccessKey")
   aws_token = resp_json.get("Token")
   print(f"Credentials : \n Access Key ID: {aws_ak}\n \n SecretAccessKey: {aws_sk}\n  \n Token:
{aws_token}")
   
   cls = get_driver(Provider.EC2)
   conn = cls(aws_ak, aws_sk, region="us-east-1")
   
   from pprint import pprint
   #pprint(conn.list_sizes())
   #pprint(dir(conn))
   pprint(conn.list_nodes())
   
   
   ================================================
   
   
   Traceback (most recent call last):
     File "test.py", line 29, in <module>
       pprint(conn.list_nodes())
     File "/home/ubuntu/.cache/pypoetry/virtualenvs/myproject-Jwnpjg_m-py3.8/lib/python3.8/site-packages/libcloud/compute/drivers/ec2.py",
line 1672, in list_nodes
       elem = self.connection.request(self.path, params=params).object
     File "/home/ubuntu/.cache/pypoetry/virtualenvs/myproject-Jwnpjg_m-py3.8/lib/python3.8/site-packages/libcloud/common/base.py",
line 655, in request
       response = responseCls(**kwargs)
     File "/home/ubuntu/.cache/pypoetry/virtualenvs/myproject-Jwnpjg_m-py3.8/lib/python3.8/site-packages/libcloud/common/base.py",
line 166, in __init__
       message=self.parse_error(),
     File "/home/ubuntu/.cache/pypoetry/virtualenvs/myproject-Jwnpjg_m-py3.8/lib/python3.8/site-packages/libcloud/compute/drivers/ec2.py",
line 1224, in parse_error
       raise InvalidCredsError(err_list[-1])
   libcloud.common.types.InvalidCredsError: 'AuthFailure: AWS was not able to validate the
provided access credentials'
   
   Distributor ID:	Ubuntu
   Description:	Ubuntu 20.04.3 LTS
   Release:	20.04
   Codename:	focal
   
   aws ec2 describe-instances --> Works as expected on this machine.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@libcloud.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



Mime
View raw message