11
獲取AWS iam中用戶的權限或組詳細信息我已成功使用python boto模塊從AWS iam中提取用戶。如何使用boto
代碼:
import boto
from boto.iam.connection import IAMConnection
cfn = IAMConnection(aws_access_key_id='somekeyid',aws_secret_access_key ='secret_here')
data = cfn.get_all_users()
for user in data.users:
print user,"\n"
How do I get the Groups details the user is associated with or the Permission type user is associated to ?
我加入這行代碼來獲取與用戶相關聯的組,我收到錯誤提到下來波紋管。
添加的代碼:
group=cfn.get_groups_for_user("Shital")
print group
其中, 「清淳」 是存在的並且是從上面獲取用戶。爲了測試目的,我手動將它傳遞給一個函數調用。
錯誤:
Traceback (most recent call last):
File "getuser.py", line 14, in <module>
pol=cfn.get_groups_for_user("Shita")
File "/home/tara/testinghere/IAM/env/local/lib/python2.7/site-packages/boto/iam/connection.py", line 509, in get_groups_for_user
list_marker='Groups')
File "/home/tara/testinghere/IAM/env/local/lib/python2.7/site-packages/boto/iam/connection.py", line 102, in get_response
raise self.ResponseError(response.status, response.reason, body)
boto.exception.BotoServerError: BotoServerError: 403 Forbidden
<ErrorResponse xmlns="https://iam.amazonaws.com/doc/2010-05-08/">
<Error>
<Type>Sender</Type>
<Code>AccessDenied</Code>
<Message>User: arn:aws:iam::586848946515:user/qa-api-users is not authorized to perform: iam:ListGroupsForUser on resource: user Shita</Message>
</Error>
<RequestId>7e9a4b56-95f0-11e7-9bb0-8b8eb22708c5</RequestId>
</ErrorResponse>
你的問題是你沒有正確的權限來執行這個操作user/qa-api-users沒有被授權執行:iam:ListGroupsForUser在資源上:user Shita'是一個強大的提示。 IIRC只有管理員用戶可以做到這一點。 –
@SteveBarnes我已檢查權限。我正在使用的憑據具有設置爲所有功能的權限。它具有對get_groups_for_user和其他每個API函數的讀訪問權限。但是我收到了用戶未授權執行的相同錯誤。根據錯誤消息它是一個權威問題,但用戶有權給予,但爲什麼我得到錯誤 –
我會建議這是AWS,Boto或庫的問題按降序排列的可能性。 –