-2

I implemented and tested the project locally with the same data in database as I have in GCP. But when I deploy my project in GCP it returns 502 every time. How can I fix this issue?
app.yaml:

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:app

runtime_config:
  python_version: 3.9

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

connection to db:

from sqlalchemy import create_engine

engines = {"rdbms": create_engine('postgresql://<user>:<password>@<public ip of instance>:5432/books_reviews')}

P.S. I only started learning GCP, so sorry if this is a stupid question. P.P.S. Repo url: https://github.com/LilJohny/BookReviewsAPI

Denys Ivanenko
  • 388
  • 7
  • 21

1 Answers1

1

I ran your code.

Had to change a few things though, like I

  • had to change the runtime to 3.7,
  • added network and subnetwork (but this is because I do not have a default network, this may not apply to you)
  • added requirements.txt with used modules.

Running the code (got 502) and going over the logs(gcloud app logs tail) I requested /rdbms/reviews/product_id/100) and it revealed the following

2021-03-23 13:57:30 default[20210323t103627]  [2021-03-23 13:57:30 +0000] [1] [CRITICAL] WORKER TIMEOUT (pid:9)
2021-03-23 13:57:31 default[20210323t103627]  [2021-03-23 13:57:31 +0000] [10] [INFO] Booting worker with pid: 10

which means that the worker is timing out for the request made, I am not sure if this is what happens to you or not, or probably this is because I do not have anything in the database. Please check the gcloud app logs tail, this should give you a hint. Tip: if you see nothing in the output of the command, give it couple of minutes, sometimes it does take a while for the output to be printed.

UPD: I am nearly positive the issue is with the authorized networks. Look under SQL - Connections - then Authorized networks. If no networks are authorized the connection will be refused and timeout will happen.

jabbson
  • 4,390
  • 1
  • 13
  • 23
  • Thanks a lot for you answer, but can you hint me why this timeout happens? I suppose that there is some permissions problem, but I don’t know which permissions do I need. – Denys Ivanenko Mar 23 '21 at 16:37
  • Sure thing, I am nearly positive the issue is with the authorized networks. Look under SQL - Connections - then Authorized networks. If no networks are authorized the connection will be refused and timeout will happen. – jabbson Mar 23 '21 at 18:06
  • Thanks a lot, these helped. Probably it would be better if you put your comments in answer. Actually I added network in the instance that was deleted, so I actually had no networks in my current instance. – Denys Ivanenko Mar 23 '21 at 20:41