Help us improve the AWS re:Post Knowledge Center by sharing your feedback in a brief survey. Your input can influence how we create and update our content to better support your AWS journey.
[AppRunner] Failed to build your application source code. Reason: Failed to execute 'build' command.
Hello, need help please I have developed an application with django that uses a postgresql database. I use aws RDS to store and manage the database and apprunner to deploy the application; but every time i deploy the application on apprunner i always get a database connection error. yet i have configured the database connection correctly in my application and in addition i have used the ec2 instances to test that the database is working correctly. here is the log error when deploying on apprunner.:
8-31-2024 12:53:30 PM [PreRun] Installing collected packages: python-decouple, django-templated-mail, distlib, whitenoise, urllib3, tzdata, typing_extensions, sqlparse, PyJWT, pycparser, psycopg2-binary, platformdirs, pillow, oauthlib, idna, gunicorn, filelock, defusedxml, charset-normalizer, certifi, asgiref, virtualenv, requests, python3-openid, Django, cffi, requests-oauthlib, djangorestframework, dj-database-url, cryptography, social-auth-core, djangorestframework-simplejwt, social-auth-app-django, djoser
08-31-2024 12:53:30 PM [PreRun] Successfully installed Django-4.2.15 PyJWT-2.9.0 asgiref-3.8.1 certifi-2024.7.4 cffi-1.17.0 charset-normalizer-3.3.2 cryptography-43.0.0 defusedxml-0.8.0rc2 distlib-0.3.8 dj-database-url-2.2.0 django-templated-mail-1.1.1 djangorestframework-3.15.2 djangorestframework-simplejwt-5.3.1 djoser-2.2.3 filelock-3.15.4 gunicorn-20.1.0 idna-3.8 oauthlib-3.2.2 pillow-10.4.0 platformdirs-4.2.2 psycopg2-binary-2.9.9 pycparser-2.22 python-decouple-3.8 python3-openid-3.2.0 requests-2.32.3 requests-oauthlib-2.0.0 social-auth-app-django-5.4.2 social-auth-core-4.5.4 sqlparse-0.5.1 typing_extensions-4.12.2 tzdata-2024.1 urllib3-2.2.2 virtualenv-20.26.3 whitenoise-6.4.0
08-31-2024 12:53:30 PM [PreRun] [91mWARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
08-31-2024 12:53:30 PM [PreRun] [0m[91m
08-31-2024 12:53:30 PM [PreRun] [notice] A new release of pip is available: 24.0 -> 24.2
08-31-2024 12:53:30 PM [PreRun] [notice] To update, run: pip3 install --upgrade pip
08-31-2024 12:53:30 PM [PreRun] [0mRemoving intermediate container 4791f2831094
08-31-2024 12:53:30 PM [PreRun] ---> 939706331547
08-31-2024 12:53:30 PM [PreRun] Step 13/15 : RUN python3.11 manage.py collectstatic --noinput
08-31-2024 12:53:30 PM [PreRun] ---> Running in b0dad7396489
08-31-2024 12:53:30 PM [PreRun] 161 static files copied to '/app/staticfiles', 463 post-processed.
08-31-2024 12:53:30 PM [PreRun] Removing intermediate container b0dad7396489
08-31-2024 12:53:30 PM [PreRun] ---> 2c18398dd75e
08-31-2024 12:53:30 PM [PreRun] Step 14/15 : RUN python3.11 manage.py migrate
08-31-2024 12:53:30 PM [PreRun] ---> Running in fc3e396ae781
08-31-2024 12:53:30 PM [PreRun] [91mTraceback (most recent call last):
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
08-31-2024 12:53:30 PM [PreRun] [0m[91m self.connect()
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
08-31-2024 12:53:30 PM [PreRun] return func(*args, **kwargs)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 270, in connect
08-31-2024 12:53:30 PM [PreRun] [0m[91m self.connection = self.get_new_connection(conn_params)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
08-31-2024 12:53:30 PM [PreRun] return func(*args, **kwargs)
08-31-2024 12:53:30 PM [PreRun] [0m[91m ^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
08-31-2024 12:53:30 PM [PreRun] [0m[91m connection = self.Database.connect(**conn_params)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/psycopg2/__init__.py", line 122, in connect
08-31-2024 12:53:30 PM [PreRun] [0m[91m conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
08-31-2024 12:53:30 PM [PreRun] [0m[91m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] psycopg2.OperationalError: connection to server at "leevlong-db.c3qsu84ky1r5.us-east-1.rds.amazonaws.com" (44.217.144.26), port 5432 failed: Connection timed out
08-31-2024 12:53:30 PM [PreRun] Is the server running on that host and accepting TCP/IP connections?
08-31-2024 12:53:30 PM [PreRun] The above exception was the direct cause of the following exception:
08-31-2024 12:53:30 PM [PreRun] Traceback (most recent call last):
08-31-2024 12:53:30 PM [PreRun] File "/app/manage.py", line 22, in <module>
08-31-2024 12:53:30 PM [PreRun] main()
08-31-2024 12:53:30 PM [PreRun] File "/app/manage.py", line 18, in main
08-31-2024 12:53:30 PM [PreRun] execute_from_command_line(sys.argv)
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
08-31-2024 12:53:30 PM [PreRun] utility.execute()
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/core/management/__init__.py", line 436, in execute
08-31-2024 12:53:30 PM [PreRun] self.fetch_command(subcommand).run_from_argv(self.argv)
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 412, in run_from_argv
08-31-2024 12:53:30 PM [PreRun] self.execute(*args, **cmd_options)
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 458, in execute
08-31-2024 12:53:30 PM [PreRun] output = self.handle(*args, **options)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/core/management/base.py", line 106, in wrapper
08-31-2024 12:53:30 PM [PreRun] res = handle_func(*args, **kwargs)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/core/management/commands/migrate.py", line 117, in handle
08-31-2024 12:53:30 PM [PreRun] executor = MigrationExecutor(connection, self.migration_progress_callback)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/migrations/executor.py", line 18, in __init__
08-31-2024 12:53:30 PM [PreRun] self.loader = MigrationLoader(self.connection)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/migrations/loader.py", line 58, in __init__
08-31-2024 12:53:30 PM [PreRun] self.build_graph()
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/migrations/loader.py", line 235, in build_graph
08-31-2024 12:53:30 PM [PreRun] self.applied_migrations = recorder.applied_migrations()
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 81, in applied_migrations
08-31-2024 12:53:30 PM [PreRun] [0m[91m if self.has_table():
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/migrations/recorder.py", line 57, in has_table
08-31-2024 12:53:30 PM [PreRun] with self.connection.cursor() as cursor:
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
08-31-2024 12:53:30 PM [PreRun] [0m[91m return func(*args, **kwargs)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 330, in cursor
08-31-2024 12:53:30 PM [PreRun] [0m[91m return self._cursor()
08-31-2024 12:53:30 PM [PreRun] [0m[91m ^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] [0m[91m File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 306, in _cursor
08-31-2024 12:53:30 PM [PreRun] [0m[91m self.ensure_connection()
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
08-31-2024 12:53:30 PM [PreRun] return func(*args, **kwargs)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 288, in ensure_connection
08-31-2024 12:53:30 PM [PreRun] with self.wrap_database_errors:
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/utils.py", line 91, in __exit__
08-31-2024 12:53:30 PM [PreRun] raise dj_exc_value.with_traceback(traceback) from exc_value
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 289, in ensure_connection
08-31-2024 12:53:30 PM [PreRun] self.connect()
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
08-31-2024 12:53:30 PM [PreRun] return func(*args, **kwargs)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/backends/base/base.py", line 270, in connect
08-31-2024 12:53:30 PM [PreRun] self.connection = self.get_new_connection(conn_params)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/utils/asyncio.py", line 26, in inner
08-31-2024 12:53:30 PM [PreRun] return func(*args, **kwargs)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/django/db/backends/postgresql/base.py", line 275, in get_new_connection
08-31-2024 12:53:30 PM [PreRun] connection = self.Database.connect(**conn_params)
08-31-2024 12:53:30 PM [PreRun] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] File "/usr/local/lib/python3.11/site-packages/psycopg2/__init__.py", line 122, in connect
08-31-2024 12:53:30 PM [PreRun] conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
08-31-2024 12:53:30 PM [PreRun] [0m[91m ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
08-31-2024 12:53:30 PM [PreRun] django.db.utils.OperationalError: connection to server at "leevlong-db.c3qsu84ky1r5.us-east-1.rds.amazonaws.com" (44.217.144.26), port 5432 failed: Connection timed out
08-31-2024 12:53:30 PM [PreRun] Is the server running on that host and accepting TCP/IP connections?
08-31-2024 12:53:30 PM [PreRun] [0mThe command '/bin/sh -c python3.11 manage.py migrate' returned a non-zero code: 1
08-31-2024 12:53:31 PM [AppRunner] Failed to build your application source code. Reason: Failed to execute 'build' command.
08-31-2024 12:53:34 PM [AppRunner] Failed to deploy your application source code.
I think apprunner can't connect to RDS. need help please.
- Language
- English
- Newest
- Most votes
- Most comments
Hello.
django.db.utils.OperationalError: connection to server at "leevlong-db.c3qsu84ky1r5.us-east-1.rds.amazonaws.com" (44.217.144.26), port 5432 failed: Connection timed out
From the error log above, I thought that public access was enabled in RDS.
Is AppRunner connected to the same VPC as RDS?
If not, please follow the steps in the document below to configure it.
https://docs.aws.amazon.com/apprunner/latest/dg/network-vpc.html
Even if AppRunner is connected to a VPC, if public access is enabled for RDS, it is possible that AppRunner is resolving the RDS endpoint using a public IP address.
Please try disabling public access for RDS.
I was able to solve the problem, I just had to go into RDS, access the database security group and add public access to postgrsql for external applications to the inbound rules. thanks
Relevant content
- asked 2 years ago
- asked 9 months ago
- asked 2 years ago
AWS OFFICIALUpdated a year ago
Yes, I have created a vpc with the subnets to link the apprunner service to the rds database but the problem still persists.
If AppRunner is connected to a VPC, disable RDS public access.