Redirect Kong non SSL to SSL

Another option to avoid modifications of kong configuration template is to use the pre-function plugin (https://docs.konghq.com/hub/kong-inc/serverless-functions/) with the following function attached to a route or a service

local scheme = kong.request.get_scheme()
if scheme == "http" then
  local host = kong.request.get_host()
  local query = kong.request.get_path_with_query()
  local url = "https://" .. host ..query
  kong.response.set_header("Location",url)
  return kong.response.exit(302,url)
end