1
votes

I have an application in Google app engine flexible which is written in Python. It uses Flask framework for backend. Currently, the flask framework serves the static files using the following code.

@app.route('/<path:path>') #Catch All urls, enabling copy-paste url
def home(path):
    return send_from_directory(CLIENT_APP_FOLDER, path)

This eats up resources for serving my website written in Angular.

I have been reading on how I could serve static files not using my app engine app. One suggestion is to use Google Cloud Storage for serving the static files but I am not able to understand how I could set my DNS so that www.example.com serves from Google Cloud Storage and www.example.com/api serves app engine app.

Another suggestion is to use dispatch.yaml and deploy two services, one pointing to the app engine app and another serving the static files, but again I am unable to figure out what the static file serving service would look like. Also does it deploy two services on the same instance or does it create two instances? I want to optimize for cost and not spin up another instance.

1

1 Answers

1
votes

There is 2 solutions for minimizing cost.

The first one is to use Cloud Run instead of appengine flex. You can deploy the same container but you pay only when you are serving request. It's in beta but it's really stable. And you can use custom domain

The second solution, if you keep your app engine flex, is to deploy a second service. This second service will serve the static resources. Use standard appengine, and customize your app.yaml for serving only static resources. Here the doc for python 2 but the configuration is language agnostic Serving static resources don't create instances. In any case, you have 28h of standard instance free per day.