Class: CfnResponse::Builder

Inherits:
Base
  • Object
show all
Defined in:
lib/cfn_response/builder.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from CfnResponse::Base

Instance Method Details

#call(input = {}) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/cfn_response/builder.rb', line 3

def call(input={})
  input.transform_keys! { |k| k.to_s }

  default = {
    "Reason" => default_reason,
    "Status" => "SUCCESS",
    "PhysicalResourceId" => physical_resource_id(input["PhysicalResourceId"])
  }
  resp = default.merge(input)

  verbatim = @event.slice("StackId", "RequestId", "LogicalResourceId") # pass these through verbatim
  verbatim.merge(resp) # final resp
end

#current_physical_resource_idObject



35
36
37
# File 'lib/cfn_response/builder.rb', line 35

def current_physical_resource_id
  @event["PhysicalResourceId"] || "PhysicalResourceId"
end

#default_reasonObject



39
40
41
# File 'lib/cfn_response/builder.rb', line 39

def default_reason
  "See the details in CloudWatch Log Group: #{@context.log_group_name} Log Stream: #{@context.log_stream_name}"
end

#new_physical_resource_idObject



27
28
29
30
31
32
33
# File 'lib/cfn_response/builder.rb', line 27

def new_physical_resource_id
  regexp = /(\d+$)/
  md = current_physical_resource_id.match(regexp) # capture trailing number
  n = md ? md[1].to_i + 1 : 1
  basename = current_physical_resource_id.sub(regexp,'') # remove trailing number
  "#{basename}#{n}"
end

#physical_resource_id(id) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/cfn_response/builder.rb', line 17

def physical_resource_id(id)
  if id.nil?
    current_physical_resource_id
  elsif id == :new_physical_resource_id or id == :new_id
    new_physical_resource_id
  else
    id
  end
end