Class: Bauble::Resources::EventBridgeRule
- Defined in:
- lib/bauble/resources/event_bridge_rule.rb
Overview
EventBridgeRule class
Instance Attribute Summary
Attributes inherited from Resource
Instance Method Summary collapse
- #add_target(function) ⇒ Object
- #bundle ⇒ Object
-
#initialize(app, name:, **kwargs) ⇒ EventBridgeRule
constructor
A new instance of EventBridgeRule.
- #synthesize ⇒ Object
Methods inherited from Resource
Constructor Details
#initialize(app, name:, **kwargs) ⇒ EventBridgeRule
Returns a new instance of EventBridgeRule.
9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/bauble/resources/event_bridge_rule.rb', line 9 def initialize(app, name:, **kwargs) super(app) @name = name @description = kwargs.fetch(:description, 'Bauble EventBridge Rule') @event_pattern = kwargs.fetch(:event_pattern, nil) @schedule_expression = kwargs.fetch(:schedule_expression, nil) @state = kwargs.fetch(:state, 'ENABLED') @event_bus_name = kwargs.fetch(:event_bus_name, 'default') @targets = [] validate_inputs end |
Instance Method Details
#add_target(function) ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/bauble/resources/event_bridge_rule.rb', line 49 def add_target(function) @targets << { "#{@name}-#{function.name}-target" => { 'type' => 'aws:cloudwatch:EventTarget', 'properties' => { 'rule' => "${#{@name}.name}", 'arn' => "${#{function.name}.arn}" } }, "#{function.name}-permission" => { 'type' => 'aws:lambda:Permission', 'properties' => { 'action' => 'lambda:InvokeFunction', 'function' => "${#{function.name}.name}", 'principal' => 'events.amazonaws.com', 'sourceArn' => "${#{@name}.arn}" } } } end |
#bundle ⇒ Object
45 46 47 |
# File 'lib/bauble/resources/event_bridge_rule.rb', line 45 def bundle true end |
#synthesize ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/bauble/resources/event_bridge_rule.rb', line 22 def synthesize event_rule_hash = { @name => { 'type' => 'aws:cloudwatch:EventRule', 'properties' => { 'name' => resource_name(@name), 'description' => @description, 'eventBusName' => @event_bus_name, 'state' => @state } } } event_rule_hash[@name]['properties']['eventPattern'] = @event_pattern.to_json if @event_pattern event_rule_hash[@name]['properties']['scheduleExpression'] = @schedule_expression if @schedule_expression @targets.each do |target| event_rule_hash.merge!(target) end event_rule_hash end |