AWS SDK for Ruby
Developer Guide

Create User Access Keys for an IAM User

The following example creates an access key and secret key for the IAM user my_groovy_user in the us-west-2 region.

require 'aws-sdk-iam' # v2: require 'aws-sdk' iam = 'us-west-2') begin user = iam.user(user_name: 'my_groovy_user') key_pair = user.create_access_key_pair puts "Access key: #{key_pair.access_key_id}" puts "Secret key: #{key_pair.secret}" rescue Aws::IAM::Errors::NoSuchEntity puts 'User does not exist' end