Can Google Cloud Endpoints run in a App Engine Module? - python

dear all
I'm trying to create a App Engine Module for hosting my api server developed with Google Cloud Endpoints. The endpoint I developed runs well in local dev environment but it responds notFound error after I deployed to remote and test it. I was guessing this might be caused by the fact that endpoints are run in a non-default module. Not sure though. Here is my module definition file (api-server.yaml):
application: myapp
module: api-server
version: dev
runtime: python27
instance_class: F2
api_version: 1
threadsafe: true
automatic_scaling:
max_idle_instances: 5
handlers:
- url: /_ah/spi/.*
script: api_dispatch.application
libraries:
- name: endpoints
version: 1.0
I plan to host endpoints with module cause my api server actually share a lot of code with my default module, which is a normal web app. Please let me know if it's possible. And sample code is very welcome.
Thanks a lot!

Yes, it's supported. I don't know why the problem happened before. But it starts working now.

Related

Deploying App on Google App Engine - Error Response: [13] An internal Error occurred

I am trying to deploy a python app on google app engine.
I was able to preview the web successfully on cloud shell editor but when I deploy it, I obtain Error Response:[13] An internal error occurred.
This is my app.yaml content
runtime: python
env: flex
entrypoint: gunicorn -b:8078 main:app
runtime_config:
python_version: 3.7
manual_scaling:
instances: 2
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
It doesn't also show logs that could indicate what is wrong with the application.
Thank you
There have been multiple iterations since the original question was asked. OP has switched from standard to flex and python27 to python37.
I think I've previously come across someone who encountered the error because they had exceeded the 1000 file limit. Since you're using python37, I assume you have a virtual environment in your project folder which you first used in running the App on your local machine. You need to have a skip_files section in your app.yaml or a .git_ignore or .gcloudignore folder and include your virtual env in it so that gcloud doesn't try to deploy it
You can also check out these other links to see if they can help you resolve your issue
https://github.com/GoogleCloudPlatform/nodejs-getting-started/issues/172
https://groups.google.com/g/google-appengine/c/M4acI1YElVs
If none of the above, I'm not sure one can figure out the solution without looking at the code. If your code is public, you can provide a link to the github.

Google Cloud Engine - How to receive an email and handle in Python 3.7?

I am using GCP to host a small Flask app and need to receive emails and process them. Having read the instructions here I have copied the sample code to test.
When I deploy I get the following error:
INVALID_ARGUMENT: script field for handler '/_ah/mail/.+' must be set
to 'auto' for runtime python37.
runtime: python37
inbound_services:
- mail
handlers:
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
- url: /_ah/mail/.+
script: handle_incoming_email.py
login: admin
If I do as the instructions suggest I'm confused because:
How can GCP know how to handle the request.. I assume it can't which is why..
I also get the following error when I change the script to auto
INVALID_ARGUMENT: login for handler '/_ah/mail/.+' is not allowed in
runtime python37.
Does GCP not support incoming email with Python 3.7 or is there a working around to have 3.7 on my Flask app and 2.7 on my mail?
Google Cloud Support here!
GCP does not support email handling with a Google App Engine application running in python 3.7, as you can see here, there's only documentation for python 2 which is the only one available.
The error you are getting in your app.yaml is due to that, and more specifically, the script field for the hanlder does not accept any other value than auto. Quoting the documentation:
Script:
Optional. Specifies that requests to the specific handler should target your app. The only accepted value for the script element is auto.
When you change your script value to auto, you are getting the INVALID_ARGUMENT error for your handler because of the incompatibility of the mail API with your python version.
Therefore in order to use the mail API, you can use third-party services as specified in the documentation. There are three recommended services:
Mailgun
Mailjet
SendGrid

GAE Doesn't Deploy Latest Code

GAE will not update the deployed code through gcloud. For instance, I created this method:
main.py
#app.route('/test',methods=['GET'])
def test():
print 'print test'
return 'test'
app.yaml
runtime: python27
api_version: 1
threadsafe: true
runtime_config:
python_version: 2
instance_class: F2
handlers:
- url: /.*
script: main.app
libraries:
- name: flask
version: 0.12
deploy the app:
gcloud app deploy app.yaml queue.yaml --project $PROJECT
Then I get a 404 when visiting /test.
I tracked down the log error:
This request caused a new process to be started for your application,
and thus caused your application code to be loaded for the first time.
This request may thus take longer and use more CPU than a typical
request for your application.
I looked at this article, which noted that I shouldn't be getting the error every time I visit the URL. I do.
I added --verbosity=info to my deployment and everything looked great except:
INFO: Could not find any remote repositories associated with
[path-to-app]. Cloud diagnostic tools may not be able to display the
correct source code for this deployment.
The code appeared updated in the dedugger, which is strange. The latest version is 100% deployed in the App Engine Dashboard.
This is really confusing because on deployment, there isn't a repo, but the code appears in the debugger but the end point won't function because there aren't enough resources.
There seems to be a lot happening here and not sure what the issue is.
Update
Some posts recommend a warmup. I followed the guidelines here and still, no dice. I'm getting a 404 when visiting /test and /_ah/warmup.
This issue could be caused by multiple different reasons, there could be a lot of factors in play, in most cases the error 404 shows when the app.yaml failed to allocate the flask library as the ‘flask’ libraries by default not bundled in the libraries the Google App Engine includes. So it needs to be added manually. One of the way to figure out if the issue is a deployment issue is to go to this link (https://console.cloud.google.com/logs/viewer) and check if there is any logs recorded or not. If there is no log appearing in the viewer it could very well mean that the problem occurred even before it actually knocks the server.
Additionally, I would highly recommend you to go through the following link (https://codelabs.developers.google.com/codelabs/cloud-vision-app-engine/index.html?index=..%2F..%2Findex#0) to deploy flask on the Google Cloud App Engine environment.
Also, I would like to make a suggestion to try a workaround using the ‘webapp2’ library if possible. The link is the following (http://webapp2.readthedocs.io/en/latest/index.html)
I have also noticed there is an attempt to run the queue.yaml. It is important to configure the file accordingly as well.
To summarize, I would really appreciate if you could try all the different possibilities to deploy the flask library and observe the results. Thank you so much.

App Engine Python 2.7 App Works on dev but make Error 500 on production

I'm deploying Python 2.7 app to Google App Engine.
The app works on local dev-server but when I try to deploy it the deployment complete successfully but any HTTP request to the app result in error 500, no matter what url I'm using.
In the App Engine logs I see the logging of the 500 response but no clue to what the problem is.
I've also try to deploy the last code that did worked and the result is the same so it doesn't looks like the code changes are the reason.
Any idea how to diagnose this problem?
You can see the code of the app.
The problem ends up being tiny mistake that I've changed the api_version from 1 to 2.
The app.yaml needs to start like this:
runtime: python27
api_version: 1
threadsafe: true
In my code it was like this which causes the error:
runtime: python27
api_version: 2
threadsafe: true

Locally test GAE task queue scaling from automatic to manual [duplicate]

This question already has answers here:
Long running program in Google App Engine
(2 answers)
Closed 6 years ago.
I am trying to change the scaling of my google app engine task queue from automatic (requires response in 10 min) to manual (extends response to 24 hr). My app.yaml file contains
application: my-application
version: alpha-1
runtime: python27
api_version: 1
threadsafe: true
I altered it to
application: my-application
version: alpha-1
runtime: python27
api_version: 1
threadsafe: true
instance_class: B1
manual_scaling:
instances: 5
I cannot deploy this to test and am trying to test locally. Unfortunately the dev_appserver.py does not timeout after 10 minutes when I use the first app.yaml configuration (it should timeout). How should I test this? Or how can I scale properly?
The instance scaling can not be tested locally - the SDK doesn't have support for the actual GAE scaling logic, you need to test it on the actual GAE infrastructure.
There are also some task queue features which aren't supported by the devserver, see Using Push Queues in the Development Server.
In order to not affect your production environment you can create a staging/development environment, for example by creating a different project & app where to deploy the same app code (with just the app ID updated). Just as the 2nd suggestion in Naming environments, for example.

Categories

Resources