details of IAM role which is attached to ec2 instances with cloudshell

0

I want view details of IAM Role to how many instances it is attached to with Cloudshell, cli which commands should use give example.

lets assume I have IAM Role TestRole I want to know to how ec2 instances TestRole is attached to.

2 Antworten
1
Akzeptierte Antwort

You will need to run this against all of your active regions to get a full count.

aws ec2 describe-instances \
    --output text \
    --region us-east-1 \
    --query Reservations[*].Instances[*].InstanceId \
    --filters Name=iam-instance-profile.arn,Values=$(aws iam list-instance-profiles-for-role \
        --role-name TestRole \
        --query InstanceProfiles[*].Arn \
        --output text) | wc -l
profile pictureAWS
EXPERTE
kentrad
beantwortet vor 2 Jahren
  • Thanks for saving so much time man. last query want view ec2 instances with no Iam role attached.

  • aws ec2 describe-instances --query 'Reservations[*].Instances[?IamInstanceProfile==null].InstanceId' --output text
    
  • Thanks again Forgot to tell I removed last thing " | wc -l " once again that this command too working great......

    aws ec2 describe-instances
    --output text
    --region us-east-1
    --query Reservations[].Instances[].InstanceId
    --filters Name=iam-instance-profile.arn,Values=$(aws iam list-instance-profiles-for-role
    --role-name TestRole
    --query InstanceProfiles[*].Arn
    --output text)

1

I am a newbie and did a little bit of research. I found this. See if it helps.

  1. Find instance profiles linked to role. https://awscli.amazonaws.com/v2/documentation/api/latest/reference/iam/list-instance-profiles-for-role.html.
  2. Then find the instance profile and instance Id associations https://docs.aws.amazon.com/cli/latest/reference/ec2/describe-iam-instance-profile-associations.html
beantwortet vor 2 Jahren

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen