Skip to content

Instantly share code, notes, and snippets.

@Hendrixer
Created December 6, 2017 22:42
Show Gist options
  • Save Hendrixer/58f56ead2d94c48a72b39210db20f2c2 to your computer and use it in GitHub Desktop.
Save Hendrixer/58f56ead2d94c48a72b39210db20f2c2 to your computer and use it in GitHub Desktop.
custom lambda plugin kong
local res, err = client:request {
method = "POST",
path = request.url,
body = request.body,
headers = request.headers
}
if not res then
return responses.send_HTTP_INTERNAL_SERVER_ERROR(err)
end
local body = res:read_body()
local json_body = cjson.decode(body)
local headers = res.headers
local ok, err = client:set_keepalive(conf.keepalive)
if not ok then
return responses.send_HTTP_INTERNAL_SERVER_ERROR(err)
end
if conf.unhandled_status
and headers["X-Amz-Function-Error"] == "Unhandled"
then
ngx.status = conf.unhandled_status
else
ngx.status = res.status
end
-- Send response to client
for k, v in pairs(headers) do
ngx.header[k] = v
end
return responses.send_HTTP_OK(json_body, headers)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment