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.
CodePudding user response:
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 using bundled services in Python 3:
- Add
app_engine_apis: true
toapp.yaml
- Add
appengine-python-standard
torequirements.txt
- Import the WSGI wrapper:
from google.appengine.api import wrap_wsgi_app
- Wrap your WSGI object (Flask):
app = Flask(__name__); app.wsgi_app = wrap_wsgi_app(app.wsgi_app)
- Review these instructions, esp. if you're not using Flask
- 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.
CodePudding user response:
Your version of gcloud probably means the app_engine_apis are in the beta version and so you have to do
gcloud beta app deploy