Create multiple IAM users using AWS CLI
After two days, I have been invited to conduct a hands-on session on Amazon Web Service (AWS) at one of the University of Gujarat. Conducting hands-on sessions has a primary constraint to have the login credentials of each and every participant. Fortunately, I am having enough credits in my account, hence I have decided to create an IAM account for the individual student. This can be done through the AWS management console or AWS CLI. Using the AWS management console, I have to do it manually for each student, which is very time-consuming. Hence, I have decided to use AWS CLI, as it can be used with the scripting language of the operating system. So in this article, I am writing the steps to create multiple users with a single shell script on the Linux. (Assumption: AWS CLI account has enough credential to create a new user with appropriate permission)
Step 1) Connect to EC2 Linux instance using putty.
Step 2) Create a text file having a list of user names for which you want to create an AWS account. The user names are line separated. (e.g. UserList.txt)
nano UserList.txt
Step 3) Type the following command to configure the root user credential.
aws configure
Step 4) Provide your access key and secret key to configure the user account.
Step 5) Create a shell script file using the following command.
nano users.sh
Step 6) add the following script to the users.sh
#!/bin/bash
while read user
do
password=”abcd1234"
aws iam create-user — user-name “$user”
aws iam attach-user-policy — user-name=”$user” — policy-arn=arn:aws:iam::aws:policy/AdministratorAccess
aws iam create-login-profile — user-name=”$user” — password=”$password” — password-reset-required
echo “created $user with password $password”
done < UserList.txt
Step 7) Once the users.sh bash is ready then execute the following command to create users listed in UserList.txt file.
bash users.sh