Search code examples
python-3.xgoogle-app-enginegoogle-cloud-sdk

Unexpected attribute app_engine_apis error deploying Python 3 App Engine Flask app


I use Google App Engine standard environemment with Flask Python3 for a current project. This project use as cache the App Engine Memcache (google.appengine.api.memcache).

Currently the cache doesn't work and I think that it's probably because of the dependency on App Engine APIs that need to be enable because when I try to deploy my app (gcloud app deploy) I have this warning: WARNING: There is a dependency on App Engine APIs, but they are not enabled in your app.yaml. Set the app_engine_apis property.

My issue is that when I try to set the dependancy in my app.yaml and deploy, I have then this error: Unexpected attribute 'app_engine_apis' for object of type AppInfoExternal.

I also tried with the exact same yaml file than the Google example: https://github.com/googlecodelabs/migrate-python2-appengine/blob/master/mod12b-memcache/app.yaml, it doesn't work.

Here the current app.yaml that I'm trying to use:

runtime: python39
env: standard
app_engine_apis: true

resources:
  cpu: 2
  memory_gb: 4
  disk_size_gb: 15

manual_scaling:
  instances: 2

This issue is almost the same as this question but I couldn't use it to solve my problem: How to deal with `app_engine_apis` warning when updating app.yaml from go114 to go115

Thank you for your help.


Solution

  • Your Google Cloud SDK is outdated. Per the comments in @NoCommandLine's answer, your SDK being version 300 is from Jul 2020 whereas the bundled services for 2nd-gen runtimes like Python 3 didn't go into private preview until Jun 2021. They became generally available in Sep 2021. If you run gcloud components update to get the latest SDK (at the time of this post, it's 410), you should be able to run gcloud app deploy to deploy a Python 3 App Engine app that can access the Memcache bundled service. TL;DR To use bundled services in Python 3:

    1. Add app_engine_apis: true to app.yaml
    2. Add appengine-python-standard to requirements.txt
    3. Import the WSGI wrapper: from google.appengine.api import wrap_wsgi_app
    4. Wrap your WSGI object (Flask): app = Flask(__name__); app.wsgi_app = wrap_wsgi_app(app.wsgi_app)
    5. Review these instructions, esp. if you're not using Flask
    6. Update your Cloud SDK: gcloud components update

    NOTE: You no longer need to run pip install -t lib -r requirements.txt to vendor/self-bundle package dependencies... they're now automatically installed for Py3 users (but not Py2 though) when you deploy your app to the cloud.

    I recently published a video & codelab (hands-on tutorial) on how to access the bundled services from "Gen2" but realize now I should've mentioned updating your SDK, meaning it covers almost all of the instructions above. :P

    For those interested in eventually migrating off Memcache to something more powerful like Redis, I also published content on migrating from Memcache to Cloud Memorystore for Redis, relatively recently as well.