I'm trying to get list of roles with special tags
Python version 3.9
Boto3 version 1.16.25
There is my code
iam = boto3.client('iam', region_name='us-east-1')
roles = iam.list_roles()["Roles"]
print(roles)
Result:
{
"Path":"/",
"RoleName":"aws-***-delivery-role",
"RoleId":"AROA****LOIO",
"Arn":"arn:aws:iam::448*****770:role/aws-***-delivery-role",
"CreateDate":datetime.datetime(2017, 11, 28, 21, 13, 3, "tzinfo=tzutc())",
"AssumeRolePolicyDocument":{
"Version":"2012-10-17",
"Statement":[
{
"Sid":"",
"Effect":"Allow",
"Principal":{
"Service":"firehose.amazonaws.com"
},
"Action":"sts:AssumeRole",
"Condition":{
"StringEquals":{
"sts:ExternalId":"448***770"
}
}
}
]
},
"MaxSessionDuration":3600
}
I don't event see a tags
I have tried this code too
iam = boto3.resource('iam', region_name='us-east-1')
roles = iam.roles.all()
But the same those roles don't have tags
Only when I run this code I could see a tag and then filtrate it, but role.load() each time do API call to AWS and I have 3k roles without role.load() it doesn't work. In result it is so long
iam = boto3.resource('iam', region_name='us-east-1')
roles = iam.roles.all()
for role in roles:
role.load()
print(role.tags)
Please, give me some advice about it or share your experience, how can I filtrate list of roles by tags?
I sow this documentation https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/iam.html#IAM.Client.list_roles
list_roles should return JSON with tags but this doesn't work