0

So, I have a service deployed to ECS, I'm trying to send an HTTP request to that service using the following code:

connection = http.client.HTTPConnection(url)

rawRequest={
    "BotAlias": "botName",
    "UserID": "user",
    "AudioFile": base64.b64encode(audio).decode("utf-8")
}

data = json.dumps(rawRequest)

connection.request("POST", "/service-path/protobuf-call",
                   data, {"Content-type": "application/json"})

response = connection.getresponse()
print(response.read())


return json.loads(response.read().decode()) 

The rule for port 80 of my ALB is to redirect to port 443 with status code of HTTP_301. For port 443, I have a default rule to redirect to each service's target group depending on the path of the request. However, when I actually run the service I keep getting 301 as the response and not the lex bot response I was looking for. Any thoughts? Thanks in advance!

Mark B
  • 183,023
  • 24
  • 297
  • 295
  • This question is really unrelated to AWS load balancers or Lex. Your Python code is simply taking the first response it receives instead of looking at the 301 redirect response and issuing another response to the redirected location. It would obviously be more efficient (less network traffic) if you simply configured your application to use HTTPS at port 443 all the time, but if you want your code to handle being redirected you should search for "Python Follow Redirects". – Mark B May 20 '20 at 12:49
  • Possible duplicate https://stackoverflow.com/questions/110498/is-there-an-easy-way-to-request-a-url-in-python-and-not-follow-redirects/14678220#14678220 – Mark B May 20 '20 at 12:50

1 Answers1

1

I solved it by using HTTPS instead of HTTP.