Class: AWS::CloudFormation::Helper::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/aws_cloudformation_helper/event.rb

Overview

Creates an Event object based on the event data from CloudFormation

Class Attribute Summary collapse

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(event, create_method, delete_method, update_method) ⇒ Event

Returns a new instance of Event.



22
23
24
25
26
27
28
29
30
# File 'lib/aws_cloudformation_helper/event.rb', line 22

def initialize(event, create_method, delete_method, update_method)
  parse_event_data(event)

  @cfn_response = AWS::CloudFormation::Helper::Response.new
  @create_method = create_method
  @delete_method = delete_method
  @update_method = update_method
  @response_data = {}
end

Class Attribute Details

.instanceObject

Returns the value of attribute instance.



9
10
11
# File 'lib/aws_cloudformation_helper/event.rb', line 9

def instance
  @instance
end

Instance Attribute Details

#logical_resource_idObject (readonly)

Returns the value of attribute logical_resource_id.



12
13
14
# File 'lib/aws_cloudformation_helper/event.rb', line 12

def logical_resource_id
  @logical_resource_id
end

#physical_resource_idObject (readonly)

Returns the value of attribute physical_resource_id.



13
14
15
# File 'lib/aws_cloudformation_helper/event.rb', line 13

def physical_resource_id
  @physical_resource_id
end

#request_idObject (readonly)

Returns the value of attribute request_id.



17
18
19
# File 'lib/aws_cloudformation_helper/event.rb', line 17

def request_id
  @request_id
end

#request_typeObject (readonly)

Returns the value of attribute request_type.



18
19
20
# File 'lib/aws_cloudformation_helper/event.rb', line 18

def request_type
  @request_type
end

#resource_propertiesObject (readonly)

Returns the value of attribute resource_properties.



14
15
16
# File 'lib/aws_cloudformation_helper/event.rb', line 14

def resource_properties
  @resource_properties
end

#resource_typeObject (readonly)

Returns the value of attribute resource_type.



15
16
17
# File 'lib/aws_cloudformation_helper/event.rb', line 15

def resource_type
  @resource_type
end

#response_dataObject

Returns the value of attribute response_data.



20
21
22
# File 'lib/aws_cloudformation_helper/event.rb', line 20

def response_data
  @response_data
end

#response_urlObject (readonly)

Returns the value of attribute response_url.



16
17
18
# File 'lib/aws_cloudformation_helper/event.rb', line 16

def response_url
  @response_url
end

#stack_idObject (readonly)

Returns the value of attribute stack_id.



19
20
21
# File 'lib/aws_cloudformation_helper/event.rb', line 19

def stack_id
  @stack_id
end

Instance Method Details

#executeObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/aws_cloudformation_helper/event.rb', line 32

def execute
  Helper.logger.debug("Request Type: #{@request_type}")

  case @request_type.downcase
  when 'create'
    execute_create
  when 'delete'
    execute_delete
  when 'update'
    execute_update
  else
    err_msg = "Invalid request type specified. Request Type: #{@request_type}"
    Helper.logger.error(err_msg)
    @cfn_response.failure(err_msg)
    raise err_msg
  end
end

#execute_createObject



50
51
52
53
54
55
56
57
58
# File 'lib/aws_cloudformation_helper/event.rb', line 50

def execute_create
  Helper.logger.info('Executing method for create event')

  @create_method.call
  @cfn_response.success
rescue StandardError => e
  @cfn_response.failure(e)
  raise e
end

#execute_deleteObject



60
61
62
63
64
65
66
67
68
# File 'lib/aws_cloudformation_helper/event.rb', line 60

def execute_delete
  Helper.logger.info('Executing method for delete event')

  @delete_method.call
  @cfn_response.success
rescue StandardError => e
  @cfn_response.failure(e)
  raise e
end

#execute_updateObject



70
71
72
73
74
75
76
77
78
# File 'lib/aws_cloudformation_helper/event.rb', line 70

def execute_update
  Helper.logger.info('Executing method for update event')

  @update_method.call
  @cfn_response.success
rescue StandardError => e
  @cfn_response.failure(e)
  raise e
end

#update_physical_resource_id(physical_resource_id) ⇒ Object



80
81
82
83
84
85
# File 'lib/aws_cloudformation_helper/event.rb', line 80

def update_physical_resource_id(physical_resource_id)
  return false unless @physical_resource_id.to_s.empty?

  @physical_resource_id = physical_resource_id
  true
end