Task: I am trying to get list of Old IAM access key users and specific tag attached to those users. All IAM users has tag (key: email and Value: xyz@gmail.com). I am not good in bash script.
Implemented so far:
#!/bin/bash today=$(date +"%Y-%m-%d") echo "Collect information about aged IAM key users" for users in $(IAM_User_Name= aws iam list-users --query 'Users[*].UserName' --output text); do user_key1_date=$(aws iam list-access-keys --user-name "$user" --output text --query 'AccessKeyMetadata[*].[AccessKeyId,CreateDate]' | awk '{ print $2 }') dtSec=$(date --date "$user_key1_date" +'%s') taSec=$(date --date "$today" +'%s') echo "INFO: dtSec=$dtSec, taSec=$taSec" >&2 [ $dtSec -lt $taSec ] && echo "$users" for user in $users; do usersemail=$(aws iam list-user-tags --user-name $user --query 'Tags[*].Key[]') echo "$usersemail" done done
This doesn't give me the proper list of users and it's email. Please guide on this.
https://stackoverflow.com/questions/65821041/old-iam-access-key-users-list-with-specified-tag-using-aws-cli-command-script January 21, 2021 at 12:06PM
没有评论:
发表评论