AWS - Rename IAM User name
Once the user is created, making a change to the account is not a regular task. Usually, modifications to access keys and ssh keys for Automation operations is the key operation. Here we will demonstrate how to modify IAM user account to change its name.
- Any policies attached to the user stay with the user under the new name.
- The user stays in the same groups under the new name.
- The unique ID for the user remains the same.
- Any resource or role policies that refer to the user as a principal (the user is being granted access) are automatically updated to use the new name or path.
Step 1: Configure AWS CLI
Please note that there is no option in the AWS console to rename a user. To change a user’s name or path, you must use the AWS CLI, Tools for Windows PowerShell, or AWS API.
For this operation, you’ll need the latest major version of AWS CLI.
Install and Use AWS CLI on Linux
Once configured, confirm it is working:
$ aws s3 ls
2020-04-04 22:49:47 ami-image-bucket
2019-11-20 18:27:47 mydemo-bucket
Step 2: Let’s Create an IAM User
Let’s create a Demo user that we’ll change its name later. I’ll create a user called pdsuser
aws iam create-user --user-name pdsuser
This the command execution output:
"User": {
"Path": "/",
"UserName": "pdsuser",
"UserId": "AIDARX4Y6JA3CZXGXGR5J",
"Arn": "arn:aws:iam::120942969046:user/pdsuser",
"CreateDate": "2020-05-26T16:14:51Z"
}
}
Step 2: Rename IAM User on AWS
We’ll use the command syntax:
aws iam update-user --user-name <Oldname> --new-user-name <Newname>
I’ll change the name of the user I created from pdsuser to pdsops:
aws iam update-user --user-name pdsuser --new-user-name pdsops
Confirm the change:
$ aws iam list-users | grep pdsops -A 2 -B 2
{
"Path": "/",
"UserName": "pdsops",
"UserId": "AIDARX4Y6JA3CZXGXGR5J",
"Arn": "arn:aws:iam::120042965046:user/pdsops",
"CreateDate": "2020-05-26T16:14:51Z"
}
I can now delete the test user using the new name:
aws iam delete-user --user-name pdsops