Class: CfnResponse::Sender
- Inherits:
-
Base
- Object
- Base
- CfnResponse::Sender
show all
- Defined in:
- lib/cfn_response/sender.rb
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#call(response_data) ⇒ Object
6
7
8
9
10
|
# File 'lib/cfn_response/sender.rb', line 6
def call(response_data)
puts "Sending #{response_data["Status"]} Status to CloudFormation"
url = @event['ResponseURL']
http_request(url, response_data)
end
|
#http_request(url, response_data) ⇒ Object
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
# File 'lib/cfn_response/sender.rb', line 12
def http_request(url, response_data)
uri = URI(url)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = uri.scheme == "https"
http.max_retries = 1 http.open_timeout = http.read_timeout = 20
req = Net::HTTP::Put.new(url)
body = JSON.dump(response_data)
req.body = body
req.content_length = body.bytesize
req['content-type'] = ''
req['content-length'] = body.bytesize
res = http.request(req)
puts "status code: #{res.code}"
puts "headers: #{res..to_h.inspect}"
puts "body: #{res.body}"
res
end
|