Class: Aws::IAM::InstanceProfile
- Inherits:
-
Object
- Object
- Aws::IAM::InstanceProfile
- Extended by:
- Deprecations
- Defined in:
- lib/aws-sdk-iam/instance_profile.rb
Defined Under Namespace
Classes: Collection
Read-Only Attributes collapse
-
#arn ⇒ String
The Amazon Resource Name (ARN) specifying the instance profile.
-
#create_date ⇒ Time
The date when the instance profile was created.
-
#instance_profile_id ⇒ String
The stable and unique string identifying the instance profile.
- #name ⇒ String (also: #instance_profile_name)
-
#path ⇒ String
The path to the instance profile.
Actions collapse
- #add_role(options = {}) ⇒ EmptyStructure
- #delete(options = {}) ⇒ EmptyStructure
- #remove_role(options = {}) ⇒ EmptyStructure
Associations collapse
- #identifiers ⇒ Object deprecated private Deprecated.
- #roles ⇒ Role::Collection
Instance Method Summary collapse
- #client ⇒ Client
-
#data ⇒ Types::InstanceProfile
Returns the data for this InstanceProfile.
-
#data_loaded? ⇒ Boolean
Returns ‘true` if this resource is loaded.
-
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the InstanceProfile exists.
-
#initialize(*args) ⇒ InstanceProfile
constructor
A new instance of InstanceProfile.
-
#load ⇒ self
(also: #reload)
Loads, or reloads #data for the current InstanceProfile.
-
#wait_until(options = {}) {|resource| ... } ⇒ Resource
deprecated
Deprecated.
Use [Aws::IAM::Client] #wait_until instead
- #wait_until_exists(options = {}, &block) ⇒ InstanceProfile
Constructor Details
#initialize(name, options = {}) ⇒ InstanceProfile #initialize(options = {}) ⇒ InstanceProfile
Returns a new instance of InstanceProfile.
22 23 24 25 26 27 28 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 22 def initialize(*args) = Hash === args.last ? args.pop.dup : {} @name = extract_name(args, ) @data = .delete(:data) @client = .delete(:client) || Client.new() @waiter_block_warned = false end |
Instance Method Details
#add_role(options = {}) ⇒ EmptyStructure
262 263 264 265 266 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 262 def add_role( = {}) = .merge(instance_profile_name: @name) resp = @client.add_role_to_instance_profile() resp.data end |
#arn ⇒ String
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*.
[1]: docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html
69 70 71 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 69 def arn data[:arn] end |
#client ⇒ Client
82 83 84 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 82 def client @client end |
#create_date ⇒ Time
The date when the instance profile was created.
75 76 77 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 75 def create_date data[:create_date] end |
#data ⇒ Types::InstanceProfile
Returns the data for this Aws::IAM::InstanceProfile. Calls Client#get_instance_profile if #data_loaded? is ‘false`.
102 103 104 105 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 102 def data load unless @data @data end |
#data_loaded? ⇒ Boolean
110 111 112 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 110 def data_loaded? !!@data end |
#delete(options = {}) ⇒ EmptyStructure
273 274 275 276 277 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 273 def delete( = {}) = .merge(instance_profile_name: @name) resp = @client.delete_instance_profile() resp.data end |
#exists?(options = {}) ⇒ Boolean
Returns ‘true` if the InstanceProfile exists.
117 118 119 120 121 122 123 124 125 126 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 117 def exists?( = {}) begin wait_until_exists(.merge(max_attempts: 1)) true rescue Aws::Waiters::Errors::UnexpectedError => e raise e.error rescue Aws::Waiters::Errors::WaiterFailed false end end |
#identifiers ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
320 321 322 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 320 def identifiers { name: @name } end |
#instance_profile_id ⇒ String
The stable and unique string identifying the instance profile. For more information about IDs, see [IAM Identifiers] in the *IAM User Guide*.
[1]: docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html
57 58 59 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 57 def instance_profile_id data[:instance_profile_id] end |
#load ⇒ self 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
92 93 94 95 96 |
# File '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 |
#name ⇒ String Also known as: instance_profile_name
33 34 35 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 33 def name @name end |
#path ⇒ String
The path to the instance profile. For more information about paths, see [IAM Identifiers] in the *IAM User Guide*.
[1]: docs.aws.amazon.com/IAM/latest/UserGuide/Using_Identifiers.html
45 46 47 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 45 def path data[:path] end |
#remove_role(options = {}) ⇒ EmptyStructure
297 298 299 300 301 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 297 def remove_role( = {}) = .merge(instance_profile_name: @name) resp = @client.remove_role_from_instance_profile() resp.data end |
#roles ⇒ Role::Collection
306 307 308 309 310 311 312 313 314 315 316 |
# File '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
Use [Aws::IAM::Client] #wait_until instead
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() {|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
225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 225 def wait_until( = {}, &block) self_copy = self.dup attempts = 0 [:max_attempts] = 10 unless .key?(:max_attempts) [:delay] ||= 10 [:poller] = Proc.new do attempts += 1 if block.call(self_copy) [:success, self_copy] else self_copy.reload unless attempts == [:max_attempts] :retry end end Aws::Waiters::Waiter.new().wait({}) end |
#wait_until_exists(options = {}, &block) ⇒ InstanceProfile
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/aws-sdk-iam/instance_profile.rb', line 134 def wait_until_exists( = {}, &block) , params = () waiter = Waiters::InstanceProfileExists.new() yield_waiter_and_warn(waiter, &block) if block_given? waiter.wait(params.merge(instance_profile_name: @name)) InstanceProfile.new({ name: @name, client: @client }) end |