Class: ElasticWhenever::Task::Role
- Inherits:
-
Object
- Object
- ElasticWhenever::Task::Role
- Defined in:
- lib/elastic_whenever/task/role.rb
Instance Method Summary collapse
- #arn ⇒ Object
- #create ⇒ Object
- #exists? ⇒ Boolean
-
#initialize(option) ⇒ Role
constructor
A new instance of Role.
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 = Aws::IAM::Client.new(option.aws_config) @resource = Aws::IAM::Resource.new(client: client) @role_name = option.iam_role @role = resource.role(@role_name) end |
Instance Method Details
#arn ⇒ Object
27 28 29 |
# File 'lib/elastic_whenever/task/role.rb', line 27 def arn role&.arn end |
#create ⇒ Object
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
21 22 23 24 25 |
# File 'lib/elastic_whenever/task/role.rb', line 21 def exists? !!arn rescue Aws::IAM::Errors::NoSuchEntity false end |