AWS SDK for Ruby
Developer Guide

Adding a New IAM User

The following example creates the IAM user my_groovy_user in the us-west-2 region with the password REPLACE_ME, and displays the user's account ID. If a user with that name already exists, it displays a message and does not create a new user.

require 'aws-sdk-iam' # v2: require 'aws-sdk' iam = Aws::IAM::Client.new(region: 'us-west-2') begin user = iam.create_user(user_name: 'my_groovy_user') iam.wait_until(:user_exists, user_name: 'my_groovy_user') user.create_login_profile({password: 'REPLACE_ME'}) arn_parts = user.arn.split(':') puts 'Account ID: ' + arn_parts[4] rescue Aws::IAM::Errors::EntityAlreadyExists puts 'User already exists' end