There are more AWS SDK examples available in the AWS Doc SDK Examples
Use CreateLoginProfile with a CLI
The following code examples show how to use CreateLoginProfile.
- CLI
-
- AWS CLI
-
To create a password for an IAM user
To create a password for an IAM user, we recommend using the
--cli-input-jsonparameter to pass a JSON file that contains the password. Using this method, you can create a strong password with non-alphanumeric characters. It can be difficult to create a password with non-alphanumeric characters when you pass it as a command line parameter.To use the
--cli-input-jsonparameter, start by using thecreate-login-profilecommand with the--generate-cli-skeletonparameter, as in the following example.aws iam create-login-profile \ --generate-cli-skeleton>create-login-profile.jsonThe previous command creates a JSON file called create-login-profile.json that you can use to fill in the information for a subsequent
create-login-profilecommand. For example:{ "UserName": "Bob", "Password": "&1-3a6u:RA0djs", "PasswordResetRequired": true }Next, to create a password for an IAM user, use the
create-login-profilecommand again, this time passing the--cli-input-jsonparameter to specify your JSON file. The followingcreate-login-profilecommand uses the--cli-input-jsonparameter with a JSON file called create-login-profile.json.aws iam create-login-profile \ --cli-input-jsonfile://create-login-profile.jsonOutput:
{ "LoginProfile": { "UserName": "Bob", "CreateDate": "2015-03-10T20:55:40.274Z", "PasswordResetRequired": true } }If the new password violates the account password policy, the command returns a
PasswordPolicyViolationerror.To change the password for a user that already has one, use
update-login-profile. To set a password policy for the account, use theupdate-account-password-policycommand.If the account password policy allows them to, IAM users can change their own passwords using the
change-passwordcommand.For more information, see Managing passwords for IAM users in the AWS IAM User Guide.
-
For API details, see CreateLoginProfile
in AWS CLI Command Reference.
-
- PowerShell
-
- Tools for PowerShell V4
-
Example 1: This example creates a (temporary) password for the IAM user named Bob, and sets the flag that requires the user to change the password the next time
Bobsigns in.New-IAMLoginProfile -UserName Bob -Password P@ssw0rd -PasswordResetRequired $trueOutput:
CreateDate PasswordResetRequired UserName ---------- --------------------- -------- 4/14/2015 12:26:30 PM True Bob-
For API details, see CreateLoginProfile in AWS Tools for PowerShell Cmdlet Reference (V4).
-
- Tools for PowerShell V5
-
Example 1: This example creates a (temporary) password for the IAM user named Bob, and sets the flag that requires the user to change the password the next time
Bobsigns in.New-IAMLoginProfile -UserName Bob -Password P@ssw0rd -PasswordResetRequired $trueOutput:
CreateDate PasswordResetRequired UserName ---------- --------------------- -------- 4/14/2015 12:26:30 PM True Bob-
For API details, see CreateLoginProfile in AWS Tools for PowerShell Cmdlet Reference (V5).
-