How to add credentials for googleapiclient on AppEngine - python

I am using Python Google API Client by following this tutorial. I was able to run the API locally by downloading the credential JSON and running export GOOGLE_APPLICATION_CREDENTIALS="[PATH]". Now, I would like to deploy my application that uses the API to AppEngine. How can I do so? Do I have to somehow download JSON on my AppEngine machine and run export via app.yaml?

Place the JSON file inside your application directory and it will be deployed to GAE as part of your application. Then you can reference it in your app with just a file path (relative to the your app.yaml file). Easiest is to put it right beside your app.yaml file and reference it with just the filename, no file path.
The exact way to reference it may be depending on the GAE environment and runtime your app uses (which you didn't mention), exporting GOOGLE_APPLICATION_CREDENTIALS via app.yaml may be right.
You may want to check your app's handlers and ensure that you don't accidentally respond with the JSON file to a properly crafted external request - you probably don't want that file served to an external request :)

Related

How can I edit the NGINX configuration on Google App Engine flexible environment?

How can I edit the Google App Engine NGINX configuration?
There doesn't seem to be much support in the Google docs in regards to the NGINX configuration for apps running in the Google App Engine flexible environment.
My app is running fine, but I get this 413 error when I try and upload an audio file (.wav or .mp3).
413 Request Entity Too Large -- nginx
My app is running Django (python 3), with Cloud Postgres SQL and Cloud Storage enabled.
I researched the error, and it seems I can set a nginx.config file so that it includes "client_max_body_size 80M" - but like I said, there is no documentation regarding how to manually config NGINX on deploy.
Any suggestions?
You should be able to create a nginx-app.conf file in the same directory as your app.yaml file. There is an example of using the nginx configuration file in a Flex environment located here: https://github.com/GoogleCloudPlatform/getting-started-php/tree/master/4-auth .
This same file is referenced in Google's documentation here: https://cloud.google.com/appengine/docs/flexible/php/runtime#customizing_nginx
Once you have that file created, you should be able to add any property you need and then rebuild your project to see the changes take effect.
So upon contacting Google Support, the suggested solution for uploading files larger than 32MB is as follows:
"The way to circumvent App Engine's 32MB limit is to send the requests directly to Cloud Storage, for instance using the resumable upload process. You can still use App Engine to serve your app, but the clientside portion of the app would be the one handling the upload to Google Cloud Storage. For this you would have your application generate a signed URL which the client can use to gain access to your Cloud Storage bucket for the purpose of uploading an image."
I went with this solution. It saves money in the end.

How to load data into local test environment DataStore?

I need to load some data from a CSV file and populate my local test GAE environment DataStore. I figure I need to use the NDB Client Library.
My question is how to direct the operations to my local test environment rather than my production cloud environment?
Thanks.
The local datastore emulation is done by the development server itself, see Using the local Datastore.
So simply by running the script that translates the CSV file into the NDB writing calls inside the development server would get you what you need.
To run the script inside the server you can make it a part of the app itself or you can execute it (or call its relevant function) inside the Interactive Console from the local admin page, which you can access at the URL displayed when the devserver starts:
INFO 2017-09-19 13:34:40,772 admin_server.py:116] Starting admin
server at: http://localhost:8000
You can also load and use code from your app itself inside the interactive console script, just as it would be part of your app.

Deploy webapp on GAE then do changes online from GAE console

I deployed a webapp2 python application on GAE. Is there any way with which i can explore the source code or make changes in the project files from GAE console. Is it possible that if i only want to update a single .py file on already deployed app rather than again deploying the whole project?
I think you're looking for this :
https://console.cloud.google.com/code/develop
I pushed my code on Google Cloud Platform with git, and I'm able to change text files directly online.
The doc is here :
https://cloud.google.com/source-repositories/

How do I work on multiple appengine projects with python?

I need to export my blobstore from one appengine project and upload it to another project. How can I switch between projects programmatically with python?
If by "python" you mean a python GAE app's code itself - AFAIK you can't switch apps - each such code runs only inside the app specified in the .yaml file.
You could teach the exporting app project to serve the blob and for the actual transfer you could either:
have the receving app directly pulling the blobs from the exporting app
have an external (python) script pull blobs from the exporting apps and uploading them to the importing app.
Either way you'd need to write some code to actually perform the transfer.
So instead of doing that, I'd rather write and execute a one-time conversion script to move the data from blobstore (presently shown in the GAE python docs under Storing Data > Superseded Storage Solutions section on the left-side menubar) to the Datastore or GCS, both of which have better backup/restore options, including across apps :) GCS can probably be even used to share the same data across apps. And you can still serve the GCS data using the blobstore API, see Uploading files directly to Google Cloud Storage for GAE app
If you mean some external python app code - AFAIK the blobstore doesn't offer generic access directly to an external application (I might be wrong, tho). So an external app would need to go through the regular upload/download handlers of the 2 apps. So in this case switching between projects really means switching between the 2 apps' upload/download URLs.
Even for this scenario it might be worthy to migrate to GCS, which does offer direct access, see Sharing and Collaboration

use dev_appserver.py for specific file in a directory

In order to start Google app engine through the cmd i use: dev_appserver.py --port=8080, but i can't figure how does it pick a file to run from the current directory.
My question is, is there an argument specifying a file to run in the server from all possible files in the directory?
dev_appserver doesn't "run a file" at all. It launches the GAE dev environment, and routes requests using the paths defined in app.yaml just like the production version.
If you need to route your requests to a specific Python file, you should define that in app.yaml.

Categories