Both AWS accounts and IAM users can have access keys (maximum of 2). You can create new keys so that you can rotate out your old keys. You can create, delete, activate and deactivate access keys.
# for the aws account access_keys = iam.access_keys.create # for an iam user user_access_keys = iam.users['johndoe'].access_keys.create
Make sure after creating an access to retrieve the secret access key and save it somewhere safe.
access_keys = iam.access_keys.create secret = access_keys.secret
If you try to access the secret on an access key that was not newly created an error will be raised. AWS will only give the secret for a newly created access key:
access_keys = iam.access_keys.first access_keys.secret #=> oops, raises a runtime error
@return [User,nil] Returns the user these accesss keys belong to.
If this returns +nil+ then these access keys belong to the AWS account.
@param [Hash] options @option options [User] :user If present, this collection will only
represent the access keys for the given user.
# File lib/aws/iam/access_key_collection.rb, line 52 def initialize options = {} @user = options[:user] @user ? super(@user, options) : super(options) end
@param [String] access_key_id The ID of the access key. @return [AccessKey] Returns a reference to the access key with
the given +access_key_id+.
# File lib/aws/iam/access_key_collection.rb, line 77 def [] access_key_id AccessKey.new(access_key_id, new_options) end
Deletes all of the access keys from this collection.
iam.users['someuser'].access_keys.clear
@return [nil]
# File lib/aws/iam/access_key_collection.rb, line 86 def clear each{|access_key| access_key.delete } nil end
# File lib/aws/iam/access_key_collection.rb, line 62 def create options = {} options[:user_name] = user.name if user resp = client.create_access_key(options) AccessKey.new_from(:create_access_key, resp.access_key, resp.access_key.access_key_id, new_options) end
Yields once for each access key. You can limit the number of access keys
yielded using :limit
.
@param [Hash] options @option options [Integer] :limit The maximum number of access keys
to yield.
@option options [Integer] :batch_size The maximum number of
access keys received each service reqeust.
@yieldparam [AccessKey] access_key @return [nil]
# File lib/aws/iam/access_key_collection.rb, line 101 def each options = {}, &block each_options = options.dup each_options[:user_name] = user.name if user super(each_options, &block) end
@private
# File lib/aws/iam/access_key_collection.rb, line 109 def each_item response, &block response.access_key_metadata.each do |item| access_key = AccessKey.new_from(:list_access_keys, item, item.access_key_id, new_options) yield(access_key) end end
@private
# File lib/aws/iam/access_key_collection.rb, line 122 def new_options user ? { :user => user } : { :config => config } end