AWS ECS Fargate Python container different behavior than local

I’m deploying a python container to AWS ECS Fargate and recognizing a different behavior than executing the container locally, and I absolutely have no idea why.

Two differences I recognized:

  1. I tried to detect if a request is a WebSocket request with the following snippet
    if req_headers['connection'] == 'Upgrade' and req_headers['upgrade'] == 'websocket':
    

    This one I can execute local successfully, but in AWS I get KeyError: 'connection'

  2. I changed the same functionality to the following:
    def __is_web_socket_request(self, headers):
        return 'connection' in headers and headers['connection'] == 'Upgrade' 
               and 'upgrade' in headers and headers['upgrade'] == 'websocket'
    

    Locally again everything works as expected, but in AWS it’s not working because the Headers starts with a upper-case letter – so weird!

The Dockerfile uses the base image:

FROM nikolaik/python-nodejs:python3.8-nodejs12

Do I miss something completely, or why does this weir behavior happen?

Source: StackOverflow