google endpoints on flex app engine

1.2k views Asked by At

When we use endpoints with std app engine environment Following lines in app.yaml, defines the starting point of the app

- url: /_ah/spi/.*
  script: main.api 

But as flex engine uses 'gunicorn' to define the staring point as given below

entrypoint: gunicorn -b :$PORT main:app

How should define main.py of my cloud endpoint to be starting point with google app engine in flex environment ?

Edit1:

after the suggestion below from this link.

I updated my app.yaml to:

runtime: python
env: flex
entrypoint: gunicorn -b :$PORT main:api
service: s2

endpoints_api_service:
  name: echo-api.endpoints.my-project-id.cloud.goog
  config_id: my-config-id

but now while deploying, in my main.py file I get the import error

ImportError: No module named endpoints

even changing the import statment to

from google.appengine.ext import endpoints

does not help

Edit2:

I added the endpoints library to the project lib folder and also added appengine_config.py file to take care of this library, still it breaks at import endpoints.

for my directory structure refer the image below

enter image description here

3

There are 3 answers

4
Dan Cornilescu On

A summary from Quickstart for Endpoints on App Engine Flexible Environment (assuming python below, if using other language select the respective examples):

  • configure endpoints:

To configure Endpoints, replace YOUR-PROJECT-ID with your own project ID in the openapi.yaml configuration file's host field:

swagger: "2.0"
info:
  description: "A simple Google Cloud Endpoints API example."
  title: "Endpoints Example"
  version: "1.0.0"
host: "echo-api.endpoints.YOUR-PROJECT-ID.cloud.goog"
  • deploy your Open API specification:

To deploy your Open API specification, run the following gcloud command:

gcloud service-management deploy openapi.yaml

This will create a new Cloud Endpoints service with the name echo-api.endpoints.YOUR-PROJECT_ID.cloud.goog if it does not exist, and then update that service's configuration to your Open API specification.

The command returns several lines of information, including a line similar to the following:

Service Configuration [2016-04-27R2] uploaded for service
"echo-api.endpoints.[YOUR-PROJECT-ID].cloud.goog"

Make a note of the service name and the service configuration ID, it is used in the next step.

  • update your app.yaml:

Edit app.yaml to reflect the Endpoints configuration ID and add the following to enable Endpoints API Management features on App Engine Flex and add the service name and configuration ID:

beta_settings:
  use_endpoints_api_management: true

endpoints_api_service:
  name: echo-api.endpoints.[YOUR-PROJECT-ID].cloud.goog
  config_id: YOUR-CONFIG-ID # 2016-04-27R2 in this example.

Save the app.yaml file. You will need to repeat these steps and update the app.yaml file when you make changes to your Open API specification.

6
saiyr On

For Endpoints Frameworks v1.0, you have to copy the endpoints module into your app directory to deploy it on Flex. If you're using the Cloud SDK, it's located in /path/to/google-cloud-sdk/platform/google_appengine/lib/endpoints-1.0.

0
Njan On

The document/the link you refers to is Extensible Service Proxy provided by Google App Engine which uses OpenAPI specifications which can be invoked using normal http requests. The entry to your endpoint service can be restricted by making use of Access Control provided by App Engine. The entire things work only App Engine Flexible Environment.

OverView GAE endpoints on Flex

Extensible Service Proxy needs to configure differently from our tradition endpoints.

  • Deploy the open API configuration using gcloud service-management deploy openapi.yaml
  • Deploy the API backend. gcloud service-management configs list --service=[YOUR-PROJECT-ID].appspot.com
  • Replace ENDPOINTS-SERVICE-NAME and ENDPOINTS-CONFIG-ID in app.yaml, then deploy using gcloud app deploy

For App Engine Standard Environment users, a new version of Endpoints(Endpoint Framework 2.0) is available. Currently, endpoint frameworks are not supported in App Engine Flexible Environment. If you want to use your existing code, I suggest using migration to Endpoint Frameworks 2.0.