Class: ElasticWhenever::Task::Role

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

Constant Summary collapse

NAME =
"ecsEventsRole"

Instance Method Summary collapse

Constructor Details

#initialize(option) ⇒ Role

Returns a new instance of Role.



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

def initialize(option)
  client = Aws::IAM::Client.new(option.aws_config)
  @resource = Aws::IAM::Resource.new(client: client)
  @role = resource.role(NAME)
end

Instance Method Details

#arnObject



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

def arn
  role&.arn
end

#createObject



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

def create
  @role = resource.create_role(
    role_name: 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)


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

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