class CfnResponse
Constants
- VERSION
Public Class Methods
new(event, context=nil)
click to toggle source
# File lib/cfn_response.rb, line 11 def initialize(event, context=nil) @event, @context = event, context end
Public Instance Methods
failed(input={})
click to toggle source
# File lib/cfn_response.rb, line 54 def failed(input={}) input[:Status] = "FAILED" send_to_cloudformation(input) end
pause_for_cloudwatch()
click to toggle source
# File lib/cfn_response.rb, line 59 def pause_for_cloudwatch return if ENV['CFN_RESPONSE_TEST'] || ENV['CFN_RESPONSE_SEND'] sleep 10 # a little time for logs to be sent to CloudWatch end
response() { || ... }
click to toggle source
# File lib/cfn_response.rb, line 15 def response show_event if show_event? result = yield if block_given? success unless @finished pause_for_cloudwatch result rescue Exception => e puts "ERROR #{e.message}" puts "BACKTRACE:\n#{e.backtrace.join("\n")}" pause_for_cloudwatch failed end
Also aliased as: respond
send_to_cloudformation(input={})
click to toggle source
# File lib/cfn_response.rb, line 40 def send_to_cloudformation(input={}) builder = Builder.new(@event, @context) response_data = builder.call(input) sender = Sender.new(@event, @context) result = sender.call(response_data) unless ENV['CFN_RESPONSE_SEND'] == '0' @finished = true result end
show_event()
click to toggle source
# File lib/cfn_response.rb, line 33 def show_event puts("event['RequestType'] #{@event['RequestType']}") puts("event: #{JSON.dump(@event)}") puts("context: #{JSON.dump(@context)}") puts("context.log_stream_name #{@context.log_stream_name.inspect}") end
show_event?()
click to toggle source
# File lib/cfn_response.rb, line 29 def show_event? ENV['CFN_RESPONSE_VERBOSE'].nil? ? true : ENV['CFN_RESPONSE_VERBOSE'] == '1' end
success(input={})
click to toggle source
# File lib/cfn_response.rb, line 49 def success(input={}) input[:Status] = "SUCCESS" send_to_cloudformation(input) end