class AWS::CloudFormation::Helper::Event
Creates an Event
object based on the event data from CloudFormation
Attributes
instance[RW]
logical_resource_id[R]
physical_resource_id[R]
request_id[R]
request_type[R]
resource_properties[R]
resource_type[R]
response_data[RW]
response_url[R]
stack_id[R]
Public Class Methods
new(event, create_method, delete_method, update_method)
click to toggle source
# 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
Public Instance Methods
execute()
click to toggle source
# 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_create()
click to toggle source
# 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_delete()
click to toggle source
# 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_update()
click to toggle source
# 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)
click to toggle source
# 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
Private Instance Methods
parse_event_data(event)
click to toggle source
# File lib/aws_cloudformation_helper/event.rb, line 89 def parse_event_data(event) raise 'The event object from Lambda is nil.' if event.nil? @logical_resource_id = event['LogicalResourceId'].to_s @physical_resource_id = event['PhysicalResourceId'] if event.keys.include?('PhysicalResourceId') @resource_properties = event['ResourceProperties'] @resource_type = event['ResourceType'].to_s @response_url = event['ResponseURL'].to_s @request_id = event['RequestId'].to_s @request_type = event['RequestType'].to_s @stack_id = event['StackId'].to_s end
valid_json?(json)
click to toggle source
# File lib/aws_cloudformation_helper/event.rb, line 102 def valid_json?(json) ::JSON.parse(json) true rescue ::JSON::ParserError false end