Class: AWS::IAM::AccessKeyCollection
- Inherits:
-
Object
- Object
- AWS::IAM::AccessKeyCollection
- Includes:
- Collection
- Defined in:
- lib/aws/iam/access_key_collection.rb
Overview
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.
Create New 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
Secret
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
Instance Attribute Summary collapse
-
#user ⇒ User?
readonly
Returns the user these accesss keys belong to.
Instance Method Summary collapse
-
#[](access_key_id) ⇒ AccessKey
Returns a reference to the access key with the given
access_key_id
. -
#clear ⇒ nil
Deletes all of the access keys from this collection.
- #create ⇒ Object
-
#each(options = {}) {|access_key| ... } ⇒ nil
Yields once for each access key.
-
#initialize(options = {}) ⇒ AccessKeyCollection
constructor
A new instance of AccessKeyCollection.
Methods included from Core::Collection::Limitable
Methods included from Core::Collection
#each_batch, #enum, #first, #in_groups_of, #page
Constructor Details
#initialize(options = {}) ⇒ AccessKeyCollection
Returns a new instance of AccessKeyCollection.
52 53 54 55 |
# File 'lib/aws/iam/access_key_collection.rb', line 52 def initialize = {} @user = [:user] @user ? super(@user, ) : super() end |
Instance Attribute Details
#user ⇒ User? (readonly)
Returns the user these accesss keys belong to. If this returns nil
then these access keys belong to the AWS account.
60 61 62 |
# File 'lib/aws/iam/access_key_collection.rb', line 60 def user @user end |
Instance Method Details
#[](access_key_id) ⇒ AccessKey
Returns a reference to the access key with the given access_key_id
.
77 78 79 |
# File 'lib/aws/iam/access_key_collection.rb', line 77 def [] access_key_id AccessKey.new(access_key_id, ) end |
#clear ⇒ nil
Deletes all of the access keys from this collection.
iam.users['someuser'].access_keys.clear
86 87 88 89 |
# File 'lib/aws/iam/access_key_collection.rb', line 86 def clear each{|access_key| access_key.delete } nil end |
#create ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/aws/iam/access_key_collection.rb', line 62 def create = {} [:user_name] = user.name if user resp = client.create_access_key() AccessKey.new_from(:create_access_key, resp.access_key, resp.access_key.access_key_id, ) end |
#each(options = {}) {|access_key| ... } ⇒ nil
Yields once for each access key. You can limit the number of access keys yielded using :limit
.
101 102 103 104 105 |
# File 'lib/aws/iam/access_key_collection.rb', line 101 def each = {}, &block = .dup [:user_name] = user.name if user super(, &block) end |