AppRunner 504 error after 2 minutes

0

I have created a Django application that serves an API using Gunicorn. This application is working on AppRunner and there is one entrypoint that calls a lambda function. This is how the AppRunner startup script looks like:

cd green_navigation_back && python manage.py migrate && python manage.py collectstatic && gunicorn --workers 4 --timeout 6000 --log-level 'debug' green_navigation_back.wsgi

The AppRunner is inside a VPC with a NAT gateway to be able to access a RDS privately and the Lambda function.

The lambda function can take around 5 minutes to complete, because it is solving an optimization problem. This is how I call the lambda function from python:

           client_config = Config(connect_timeout=6000, read_timeout=6000)
            lambda_client = boto3.client(
                "lambda",
                region_name=settings.AWS_REGION,
                config=client_config,
            )

            lambda_response = lambda_client.invoke(
                FunctionName=settings.LAMBDA_URL,
                InvocationType="RequestResponse",
                Payload=json.dumps(request_data),
            )
            lambda_response = json.loads(lambda_response["Payload"].read())

The problem comes when I try to do a request because it gives a 504 Gateway Timeout error exactly at 2 minutes.

Error example

On the other hand, at the end of the endpoint an email is sent and sometimes even receiving a 504 error, it works and send the email. It doesn't have any sense because that would mean that the request is done asynchronously.

Email sending log

I have tried this process with the Django API in local and changed the client that makes the requests and it works. So the problem should be on AWS and more precisely in AppRunner or the VPC.

No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions