How can I write to another Google App Engine app? - python

How can I connect multiple Google App Engine apps to my one Django app engine service so that I can write to another apps datastore? Is this even possible?

Directly accessing an app's datastore from another application is possible (you don't really need to write to the app itself for that!)
The fact that the other app is also a GAE app or not doesn't really matter, setting up the access control and accessing the respective datastore are the same.
I captured the details in How do I use Google datastore for my web app which is NOT hosted in google app engine?
If you don't want to give direct datastore access to the outside app then you could implement an inter-app communication protocol to achieve what you want:
the app owning the datastore would act as a server for the other apps and would perform itself the datastore accesses on their behalf
the other apps would be clients, sending requests to the server app to get it to perform the desired actions
With this approach you can implement any access control/restriction scheme you want on the server side, which is not really possible with the direct datastore access method.

Related

How to only run Google App Engine cronjobs in Django if the caller is the Google App Engine?

I have been deployed my Django project to the Google App Engine. I wanna add cronjobs to my Django project and there is a cool feature for it in Google App Engine.
If I understand it well, I must create GET functions for my cronjobs in my views.py. But how do I make them callable only by the App Engine and no one else? Or, maybe there is a better solution for cronjobs in Django?
You can validate your request by checking header X-Appengine-Cron at your endpoint. This header is only supplied when your endpoint is triggered by GAE cron jobs.
Reference link:
https://cloud.google.com/appengine/docs/standard/python3/scheduling-jobs-with-cron-yaml#validating_cron_requests

Flask deployment

I've created a shopping site with a backend and a frontend.
The backend is python (3.6.5) with Flask.
I want to deploy my site to Google App Engine (gae).
When in development, everything works fine.
When deployed (in production) each rpc gets it's own 'thread' and everything is a mess.
I tried slapping gunicorn on it with sync and gevent worker class, but to no avail.
In deployment, how can I make each connection/session remember it's own 'instance of the backend'?
-instead of gae/flask/gunicorn serving a new instance of the backend for each request?
I need each user connection to be consistent and 'its own'/'private'.
It's not possible to do this. App Engine will spread the request load to your application across all instances, regardless of which one previously handled a request from a specific IP. A specific instance may also come online or go offline due to load or underlying changes to App Engine (e.g., a data center needs maintenance).
If you need to maintain session state between multiple requests to your app, you have a couple options depending on the architecture:
Keep session state in cookies with Flask.session
Keep session state in storage with Memorystore

Google app engine database access on localhost

I am new to Python and Google App Engine. I have installed an existing Python application on localhost, and it is running fine for the static pages. But, when I try to open a page which is fetching data, it is showing an error message:
BadRequestError: app "dev~sample-app" cannot access app "dev~template-builder"'s data
template-builder is the name of my online application. I think there is some problem with accessing the Google App Engine data on localhost. What should I do to get this to work?
Since you are just getting started I assume you don't care much about what is in your local datastore. Therefore, when starting your app, pass the --clear_datastore to dev_appserver.py.
What is happening? As daemonfire300 said, you are having conflicting application IDs here. The app you are trying to run has the ID "sample-app". Your datastore holds data for "template-builder". The easiest way to deal with it is clearing the datastore (as described above).
If you indeed want to keep both data, pass --default_partition=dev~sample-app to dev_appserver.py (or the other way around, depending on which app ID you want to use).

api app checking user permissions via a unique identifier passed from client facing app

I have a api app that sits behind a few client facing apps. The client facing apps have users that login to them and then request resources that the client facing apps in turn request from the api app.
The api app keeps track of who is allowed certain types of resources. The client facing apps are nto meant to know the details.
If i want the api app to know what client the request is for, so it can decide whether the person has permission, what should the client facing apps pass to the api app?
Should I add a unique identifier to the user model that can be used to refer to a user?
You should definitively consider the existing apps that help making an API with access control.
This should get you started in configuring your API rather than implementing it from scratch.

google appengine datastore client

Is there a tool/client to view inside and make queries for google appengine datastore?
Starting with release 1.1.9 of the App Engine SDK, however, there's a new way to interact with the datastore, in the form of the remote_api module. This module allows remote access to the App Engine datastore, using the same APIs you know and love from writing App Engine Apps.
http://code.google.com/appengine/articles/remote_api.html
And some wrapper around it:
Today, I will share with you a simple script – remote.py – which can do all the necessary staging in order for us to talk with our App Engine back-end at Google. remote.py provides a single function attach(host), which will configure the API to communicate with the specified host. This will allow us to easily write scripts that interact with the live serving application, or if we need to, a newly-deployed version.
http://blog.onideas.ws/remote_api.gae
You can login at AppSpot and go to the "Datastore Viewer". You can run custom GQL queries and view/edit entities in the datastore.

Categories

Resources