I'm writing a bash script that takes a user name from user input, and displays their AWS access keys and creation dates.
I use jq to parse the output of the command.
The output looks like this:
Enter a user name:
ralph
User ralph keys:
AKIAJS7KPHZCQRQ5FJWA
2016-08-31T15:38:18Z
AKIAICDOHVTMEAB6RM5Q
2018-02-08T03:55:51Z
How can I split that output so that the access key is listed next to the date?
I want the output to look like this:
AKIAJS7KPHZCQRQ5FJWA : 2016-08-31T15:38:18Z
AKIAICDOHVTMEAB6RM5Q : 2018-02-08T03:55:51Z
This is my code so far:
echo "Enter a user name: "
read -r user_name
keys=( $(aws iam list-access-keys --profile=prod | jq -r '.AccessKeyMetadata[] | (.AccessKeyId, .CreateDate)') )
echo "User $user_name keys:"
for key in "${keys[@]}"
do
echo "$key"
done