network error when deployed on Amazon ECS
NiharikaPatel opened this issue · 5 comments
Bukdu seems to be working fine when locally deployed on a docker container, however, it does not seem to work when pushed to ECS.
This is our code
using Bukdu
using HTTP.Messages: setheader
using JSON
using JLD
using Dates
struct SimulationController <: ApplicationController
conn::Conn
end
function take_options(c::SimulationController)
req = c.conn.request
@info :req_headers req.headers
@info :req_method_target (req.method, req.target)
setheader(req.response, "Access-Control-Allow-Headers" => (
"X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept"
))
setheader(req.response, "Access-Control-Allow-Origin" => "*")
setheader(req.response,"Access-Control-Allow-Methods" => "POST, GET, PUT, DELETE, OPTIONS")
setheader(req.response,"Access-Control-Allow-Credentials" => "false")
setheader(req.response,"Access-Control-Max-Age" => "86400")
nothing
end
function run_simulation(inputs_string::String)
timestamp = now()
@info :inputs inputs_string
#work
output = "Hello World"
return output
end
function get_http_handler(c::SimulationController)
# inputs_string = String(c.conn.request.body)
# println(c.conn.request.target)
req = c.conn.request
@info req.target
@info req.method
input_string = String(req.body)
if req.target == "/run" && req.method == "POST"
output = run_simulation(input_string))
else
output = "Not found"
end
setheader(req.response, "Access-Control-Allow-Origin" => "*")
render(JSON, output)
end
routes() do
Bukdu.options("/", SimulationController, take_options)
Bukdu.options("/run", SimulationController, take_options)
end
Bukdu.start(8080,host="0.0.0.0")
Base.JLOptions().isinteractive==0 && wait()
We tested it hosting the client on localhost 8080 and also the client hosted on AWS s3 while the back end was running locally and it worked fine but once we deployed it on AWS ECS, it did not seem to work.
hmm, need someone who know about AWS ECS
What is the difference between all the 3 cors examples. It could be a CORS error. Is there a difference in the way HTTPServer.jl worked because when we used Julia v0.6 with HttpServer.jl to deploy our webserver, we dint have any problem with ECS. Is there any settings I would need to change in Bukdu to allow that?
I don't have Amazon ECS account, it's hard to test for ECS.
if you want an example using only HTTP.jl
, here's gist
https://gist.github.com/wookay/f72e791a5bc1b1def070435cebeba490
Thanks, I tried that code but i get this error.
ERROR: LoadError: UndefVarError: RequestHandlerFunction not defined Stacktrace: [1] getproperty(::Module, ::Symbol) at ./sysimg.jl:13 [2] top-level scope at none:0 [3] include at ./boot.jl:317 [inlined] [4] include_relative(::Module, ::String) at ./loading.jl:1044 [5] include(::Module, ::String) at ./sysimg.jl:29 [6] exec_options(::Base.JLOptions) at ./client.jl:231 [7] _start() at ./client.jl:425
you need HTTP.jl v0.8.0