Reputation: 475
I'm using Google App Engine, Python37 environment.
I got an error message when trying to deploy a microservice today:
I run the command:
gcloud app deploy app.yaml
Got the error:
...
File upload done.
ERROR: (gcloud.app.deploy) INVALID_ARGUMENT: script field for handler '/.*'
must be set to 'auto' for runtime python37.
PS C:\path_to_app> gcloud app deploy app.yaml
...
My app.yaml is:
service: service_name
runtime: python37
handlers:
- url: /.*
script: main.py
It looks exactly the same from other microservices that I have deployed recently, just the service name is different.
I tried to re-deploy a services that is already running and got same error message.
So I double check app.yaml reference document: https://cloud.google.com/appengine/docs/standard/python3/config/appref
But I couldn't find out what is wrong neither why the same yaml file that had worked before doesn't work anymore.
Does anyone know what can be wrong or maybe what can be changed on Google App Engine in the last days?
Thanks in advance.
Upvotes: 9
Views: 6173
Reputation: 11167
The earlier answer from @Omair, while correct, is only part of the story. The OP's original question utilizes an App Engine first-generation ("Gen1") runtime app's app.yaml
configuration file where the routing happens, requiring the script:
directive in handlers:
. While that's a perfectly valid app.yaml
for a Gen1 (go111
, python
[2.5], python27
, php55
) app, it won't work for next generation ("Gen2") apps.
NOTE: Python 2 is only supported by App Engine Gen1 whereas Python 3 is only supported by App Engine Gen2 (Standard or Flex), so if you migrate from Python 2 to 3, you're also porting from Gen1 to Gen2 and need to keep in mind these differences as well. (Unfortunately, this means migrating from
webapp2
to a web framework that handles routing, i.e., Django, Flask, etc.)
App Engine Gen2 requires routing to be done by your framework. As a result, all Gen1 app.yaml
files need to be updated. Use of handlers:
for your routes must be either removed or changed to auto
(because it's done by your web framework now). If you have specific app startup instructions, you can provide an entrypoint:
directive; check out these examples.
Both handlers:
and entrypoint:
are optional. If all script handlers are auto
, you don't need handlers:
unless your app is serving static files like client-side JS, CSS, HTML, images, etc., and entrypoint:
is optional because if you don't specify a server, gunicorn
is selected (and started) by default. Basically if you take all the defaults and don't serve static files, you can reduce app.yaml
down to 1 line, like this one. That sample is from a repo I'm working on to help developers upgrade Python 2 App Engine apps to Python 3 who need more help than what's available in the official migration guide.
Upvotes: 3
Reputation: 1175
I got this error when deploying a flask app with a blueprint structure. The solution is to have main.py
file in the same directory as app.yaml
file. In the main.py
file, import the app object e.g from app import app
(here the first 'app' is the folder containing an init file where the flask app instance is created). After doing this, setting script to auto should work fine.
Upvotes: 1
Reputation: 481
As per the AppEngine documentation for Python 3.7,
The only accepted value for the script element is auto
Below is a sample entry from the documentation:
handlers:
- url: /images
static_dir: static/images
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
Upvotes: 16