'Unable to make requests to AWS mysql in ec2 instance after delpoying through eb cli

I'm using RDS MySQL from AWS and it works on a local machine I can successfully login to Django admin using the same db also can migrate and etc. But the problem is when I deployed this project with the same settings with EB CLI via ec2 instance, the project loaded successfully. except for the db operations, that does not work properly. I can't log in into admin, and that gives 504 Gateway Time-out enter image description here

That takes 60 sec to process the request but fails every time. But db operations are working on the local machines. For example, I tried making a GET request from localhost using the same db /api/v1/categories/1/ that gives me `200 response

But when I tried from the same project hosted on ec2 instance it gives 504 response enter image description here

These are the eb configurations:

packages:
    yum:
        python3-devel: []
        mariadb-devel: []

option_settings:
  aws:elasticbeanstalk:application:environment:
    DJANGO_SETTINGS_MODULE: config.settings


  aws:elasticbeanstalk:container:python:
    WSGIPath: config.wsgi:application

Some suggest increasing HTTP request processing time. But why does it's taking too long but works on the remote connection locally? from the local Django settings. Are there any extra settings to set up to handle this problem? Or what might be the solution could be?

EDIT: This is what I get on the eb.logs while making the request

     2022/03/09 07:19:05 [error] 18456#18456: *384 upstream timed out (110: Connection timed out) while reading response header from
 upstream, client: 172.31.23.83, server: , request: "POST
 /admin/login/?next=/admin/ HTTP/1.1", upstream:
 "http://127.0.0.1:8000/admin/login/?next=/admin/", host:
"site.ap-south-1.elasticbeanstalk.com", referrer:
 "http://site.ap-south-1.elasticbeanstalk.com/admin/login/?next=/admin/"


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source