Class: ElasticWhenever::Task::Role

Inherits:
Object
  • Object
show all
Defined in:
lib/elastic_whenever/task/role.rb

Instance Method Summary collapse

Constructor Details

#initialize(option) ⇒ Role

Returns a new instance of Role.



4
5
6
7
8
9
# File 'lib/elastic_whenever/task/role.rb', line 4

def initialize(option)
  client = option.iam_client
  @resource = Aws::IAM::Resource.new(client: client)
  @role_name = option.iam_role
  @role = resource.role(@role_name)
end

Instance Method Details

#arnObject



27
28
29
# File 'lib/elastic_whenever/task/role.rb', line 27

def arn
  role&.arn
end

#createObject



11
12
13
14
15
16
17
18
19
# File 'lib/elastic_whenever/task/role.rb', line 11

def create
  @role = resource.create_role(
    role_name: @role_name,
    assume_role_policy_document: role_json,
  )
  role.attach_policy(
    policy_arn: "arn:aws:iam::aws:policy/service-role/AmazonEC2ContainerServiceEventsRole"
  )
end

#exists?Boolean

Returns:

  • (Boolean)


21
22
23
24
25
# File 'lib/elastic_whenever/task/role.rb', line 21

def exists?
  !!arn
rescue Aws::IAM::Errors::NoSuchEntity
  false
end