Class: Aws::IAM::InstanceProfile

Inherits:
Object
  • Object
show all
Defined in:
gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb

Defined Under Namespace

Classes: Collection

Actions collapse

Associations collapse

Read-Only Attributes collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, options = {}) ⇒ InstanceProfile #initialize(options = {}) ⇒ InstanceProfile

Returns a new instance of InstanceProfile.

Overloads:

  • #initialize(name, options = {}) ⇒ InstanceProfile

    Parameters:

    • name (String)

    Options Hash (options):

  • #initialize(options = {}) ⇒ InstanceProfile

    Options Hash (options):

    • :name (required, String)
    • :client (Client)


22
23
24
25
26
27
28
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 22

def initialize(*args)
  options = Hash === args.last ? args.pop.dup : {}
  @name = extract_name(args, options)
  @data = options.delete(:data)
  @client = options.delete(:client) || Client.new(options)
  @waiter_block_warned = false
end

Instance Method Details

#add_role(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance_profile.add_role({
  role_name: "roleNameType", # required
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :role_name (required, String)

    The name of the role to add.

    This parameter allows (through its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

Returns:

  • (EmptyStructure)


262
263
264
265
266
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 262

def add_role(options = {})
  options = options.merge(instance_profile_name: @name)
  resp = @client.add_role_to_instance_profile(options)
  resp.data
end

#arnString

The Amazon Resource Name (ARN) specifying the instance profile. For more information about ARNs and how to use them in policies, see IAM Identifiers in the IAM User Guide.

Returns:

  • (String)


69
70
71
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 69

def arn
  data[:arn]
end

#clientClient

Returns:



82
83
84
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 82

def client
  @client
end

#create_dateTime

The date when the instance profile was created.

Returns:

  • (Time)


75
76
77
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 75

def create_date
  data[:create_date]
end

#dataTypes::InstanceProfile

Returns the data for this Aws::IAM::InstanceProfile. Calls Client#get_instance_profile if #data_loaded? is false.

Returns:



102
103
104
105
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 102

def data
  load unless @data
  @data
end

#data_loaded?Boolean

Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.

Returns:

  • (Boolean)

    Returns true if this resource is loaded. Accessing attributes or #data on an unloaded resource will trigger a call to #load.



110
111
112
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 110

def data_loaded?
  !!@data
end

#delete(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance_profile.delete()

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Returns:

  • (EmptyStructure)


273
274
275
276
277
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 273

def delete(options = {})
  options = options.merge(instance_profile_name: @name)
  resp = @client.delete_instance_profile(options)
  resp.data
end

#exists?(options = {}) ⇒ Boolean

Returns true if the InstanceProfile exists.

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Returns:

  • (Boolean)

    Returns true if the InstanceProfile exists.



117
118
119
120
121
122
123
124
125
126
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 117

def exists?(options = {})
  begin
    wait_until_exists(options.merge(max_attempts: 1))
    true
  rescue Aws::Waiters::Errors::UnexpectedError => e
    raise e.error
  rescue Aws::Waiters::Errors::WaiterFailed
    false
  end
end

#instance_profile_idString

The stable and unique string identifying the instance profile. For more information about IDs, see IAM Identifiers in the IAM User Guide.

Returns:

  • (String)


57
58
59
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 57

def instance_profile_id
  data[:instance_profile_id]
end

#loadself Also known as: reload

Loads, or reloads #data for the current Aws::IAM::InstanceProfile. Returns self making it possible to chain methods.

instance_profile.reload.data

Returns:

  • (self)


92
93
94
95
96
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 92

def load
  resp = @client.get_instance_profile(instance_profile_name: @name)
  @data = resp.instance_profile
  self
end

#nameString Also known as: instance_profile_name

Returns:

  • (String)


33
34
35
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 33

def name
  @name
end

#pathString

The path to the instance profile. For more information about paths, see IAM Identifiers in the IAM User Guide.

Returns:

  • (String)


45
46
47
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 45

def path
  data[:path]
end

#remove_role(options = {}) ⇒ EmptyStructure

Examples:

Request syntax with placeholder values


instance_profile.remove_role({
  role_name: "roleNameType", # required
})

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :role_name (required, String)

    The name of the role to remove.

    This parameter allows (through its regex pattern) a string of characters consisting of upper and lowercase alphanumeric characters with no spaces. You can also include any of the following characters: _+=,.@-

Returns:

  • (EmptyStructure)


297
298
299
300
301
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 297

def remove_role(options = {})
  options = options.merge(instance_profile_name: @name)
  resp = @client.remove_role_from_instance_profile(options)
  resp.data
end

#rolesRole::Collection

Returns:



306
307
308
309
310
311
312
313
314
315
316
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 306

def roles
  batch = []
  data[:roles].each do |d|
    batch << Role.new(
      name: d[:role_name],
      data: d,
      client: @client
    )
  end
  Role::Collection.new([batch], size: batch.size)
end

#wait_until(options = {}) {|resource| ... } ⇒ Resource

Deprecated.

Use [Aws::IAM::Client] #wait_until instead

Note:

The waiting operation is performed on a copy. The original resource remains unchanged.

Waiter polls an API operation until a resource enters a desired state.

Basic Usage

Waiter will polls until it is successful, it fails by entering a terminal state, or until a maximum number of attempts are made.

# polls in a loop until condition is true
resource.wait_until(options) {|resource| condition}

Example

instance.wait_until(max_attempts:10, delay:5) do |instance|
  instance.state.name == 'running'
end

Configuration

You can configure the maximum number of polling attempts, and the delay (in seconds) between each polling attempt. The waiting condition is set by passing a block to #wait_until:

# poll for ~25 seconds
resource.wait_until(max_attempts:5,delay:5) {|resource|...}

Callbacks

You can be notified before each polling attempt and before each delay. If you throw :success or :failure from these callbacks, it will terminate the waiter.

started_at = Time.now
# poll for 1 hour, instead of a number of attempts
proc = Proc.new do |attempts, response|
  throw :failure if Time.now - started_at > 3600
end

  # disable max attempts
instance.wait_until(before_wait:proc, max_attempts:nil) {...}

Handling Errors

When a waiter is successful, it returns the Resource. When a waiter fails, it raises an error.

begin
  resource.wait_until(...)
rescue Aws::Waiters::Errors::WaiterFailed
  # resource did not enter the desired state in time
end

attempts attempt in seconds invoked before each attempt invoked before each wait

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

  • :max_attempts (Integer) — default: 10

    Maximum number of

  • :delay (Integer) — default: 10

    Delay between each

  • :before_attempt (Proc) — default: nil

    Callback

  • :before_wait (Proc) — default: nil

    Callback

Yield Parameters:

  • resource (Resource)

    to be used in the waiting condition.

Returns:

  • (Resource)

    if the waiter was successful

Raises:

  • (Aws::Waiters::Errors::FailureStateError)

    Raised when the waiter terminates because the waiter has entered a state that it will not transition out of, preventing success.

    yet successful.

  • (Aws::Waiters::Errors::UnexpectedError)

    Raised when an error is encountered while polling for a resource that is not expected.

  • (NotImplementedError)

    Raised when the resource does not



225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 225

def wait_until(options = {}, &block)
  self_copy = self.dup
  attempts = 0
  options[:max_attempts] = 10 unless options.key?(:max_attempts)
  options[:delay] ||= 10
  options[:poller] = Proc.new do
    attempts += 1
    if block.call(self_copy)
      [:success, self_copy]
    else
      self_copy.reload unless attempts == options[:max_attempts]
      :retry
    end
  end
  Aws::Waiters::Waiter.new(options).wait({})
end

#wait_until_exists(options = {}, &block) ⇒ InstanceProfile

Parameters:

  • options (Hash) (defaults to: {})

    ({})

Options Hash (options):

  • :max_attempts (Integer) — default: 40
  • :delay (Float) — default: 1
  • :before_attempt (Proc)
  • :before_wait (Proc)

Returns:



134
135
136
137
138
139
140
141
142
143
# File 'gems/aws-sdk-iam/lib/aws-sdk-iam/instance_profile.rb', line 134

def wait_until_exists(options = {}, &block)
  options, params = separate_params_and_options(options)
  waiter = Waiters::InstanceProfileExists.new(options)
  yield_waiter_and_warn(waiter, &block) if block_given?
  waiter.wait(params.merge(instance_profile_name: @name))
  InstanceProfile.new({
    name: @name,
    client: @client
  })
end