Method: MistAws::Iam#initialize

Defined in:
lib/mist_aws/iam.rb

#initialize(opts = {}) ⇒ MistAws::Iam

Initializes all you need to access aws resources in a region You can create multiple instances to allow access to multiple regions in one program/recipe

Parameters:

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

    the key/value pairs for the initializer

Options Hash (opts):

  • :profile_name (String) — default: 'default' or ENV['AWS_PROFILE']

    profile name to use to get creds from ~/.aws/credentials.

  • :region (String) — default: us-east-1 or ENV['AWS_REGION']

    AWS Region to use

  • :logger (Logger) — default: STDERR

    A logger instance to use for logging



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/mist_aws/iam.rb', line 32

def initialize(opts={})
  # Ruby 1.9 backwards compatability
  opts = {profile_name: nil, region: nil, logger: ::Logger.new(STDERR)}.merge(opts)
  opts.each do |key, value|
    instance_variable_set "@#{key}", value
  end

  # Set by rspec tests that are testing methods called by initialize
  return if ENV['RSPEC_IGNORE_INITIALIZE']

  @region ||= ENV['AWS_REGION'] ? ENV['AWS_REGION'] : 'us-east-1'

  # Note get_creds also resolves and sets @profile_name as well as
  # fetching the appropriate credentials based on the value of
  # profile_name and various Environment Variables
  @credentials = get_creds(profile_name)

  @iam_client = ::Aws::IAM::Client.new(credentials: @credentials, region: @region)
  @iam = ::Aws::IAM::Resource.new(client: @iam_client)
end