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回答
1
承認された回答

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
エキスパート
kentrad
回答済み 2年前
  • 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
回答済み 2年前

ログインしていません。 ログイン 回答を投稿する。

優れた回答とは、質問に明確に答え、建設的なフィードバックを提供し、質問者の専門分野におけるスキルの向上を促すものです。

質問に答えるためのガイドライン

関連するコンテンツ