AWS SDK for Ruby
Developer Guide

Managing IAM Users

An IAM user represents a person or service that interacts with AWS. For more information about IAM users, see IAM Users.

In this example, you use the AWS SDK for Ruby with IAM to:

  1. Get information about available AWS IAM users by using Aws::IAM::Client#list_users.

  2. Create a user by using Aws::IAM::Client#create_user.

  3. Update the user's name by using Aws::IAM::Client#update_user.

  4. Delete the user by using Aws::IAM::Client#delete_user.

Prerequisites

Before running the example code, you need to install and configure the AWS SDK for Ruby, as described in:

Example

require 'aws-sdk-iam' # v2: require 'aws-sdk' iam = Aws::IAM::Client.new(region: 'us-east-1') user_name = "my-user" changed_user_name = "my-changed-user" # Get information about available AWS IAM users. def list_user_names(iam) list_users_response = iam.list_users list_users_response.users.each do |user| puts user.user_name end end puts "User names before creating user..." list_user_names(iam) # Create a user. puts "\nCreating user..." iam.create_user({ user_name: user_name }) puts "\nUser names after creating user..." list_user_names(iam) # Update the user's name. puts "\nChanging user's name..." begin iam.update_user({ user_name: user_name, new_user_name: changed_user_name }) puts "\nUser names after updating user's name..." list_user_names(iam) rescue Aws::IAM::Errors::EntityAlreadyExists puts "User '#{user_name}' already exists." end # Delete the user. puts "\nDeleting user..." iam.delete_user({ user_name: changed_user_name }) puts "\nUser names after deleting user..." list_user_names(iam)

On this page: