How to run hostedTarget nodejs code in apigee X. In apigee X does not allow HostedTargets

Hi Apigee Community.

In Apigee Edge we have "Hosted Target" to run the server less nodejs code. In apigee X "Hosted Target" is removed. Kindly suggest how can i run my Nodejs in Apigee X.  Is there any alternative way to run nodejs code by deploying code in server less environment and run the code by calling url. I found some videos on youtube about Cloud Run. If anyone implemented this in apigee X using Cloud Run, Please share the steps and sample code.

Thanks.

Solved Solved
0 3 407
1 ACCEPTED SOLUTION

Apigee X does not allow HostedTargets. It's not supported.

Some history, for those who are interested: the Hosted Target feature was a way for you to bundle your nodejs code with your API Proxy configuration, and deploy them as one unit. In fact the Hosted Target feature was intended to be a replacement for nodejs targets, which was an ingenious way to introduce instability into the Message Processor, by allowing anyone to write nodejs code that runs in-process. That  is what the node target did, running on Rhino + Trireme, within the JVM.  Hosted Targets was a huge improvement over that model, delegating the running of the nodejs code to... I think Google App Engine. This was much better than the node target, much more reliable. But still there are compromises with this Hosted Targets model. 

With the move to Google Cloud, it does not make sense to "bundle" nodejs code with the API proxy any longer. I suggest that you build and run your nodejs app in Cloud Run. It's easy to do, and it will perform well. Keep the API proxy configuration in Apigee.

I am not an expert on Cloud Run, but for nodejs apps, deploying your code to cloud run could be as simple as:

 

gcloud components update

REGION=us-west1
gcloud config set run/region $REGION

PROJECT_ID=my-gcp-project-1
gcloud config set core/project $PROJECT_ID

gcloud run deploy my-nodejs-app --source . 

 

This is from https://cloud.google.com/run/docs/setup . This works for me, for all of my apps.

The output of that will give you an endpoint. You can then connect from your Apigee X proxy into that cloud run endpoint, using Google Authentication. You'll need to grant the role roles/run.invoker to the service account , to allow it to invoke that cloud run service. More on that here. (Though the endpoint is public it will be restricted from outside invocation.)

View solution in original post

3 REPLIES 3

Apigee X does not allow HostedTargets. It's not supported.

Some history, for those who are interested: the Hosted Target feature was a way for you to bundle your nodejs code with your API Proxy configuration, and deploy them as one unit. In fact the Hosted Target feature was intended to be a replacement for nodejs targets, which was an ingenious way to introduce instability into the Message Processor, by allowing anyone to write nodejs code that runs in-process. That  is what the node target did, running on Rhino + Trireme, within the JVM.  Hosted Targets was a huge improvement over that model, delegating the running of the nodejs code to... I think Google App Engine. This was much better than the node target, much more reliable. But still there are compromises with this Hosted Targets model. 

With the move to Google Cloud, it does not make sense to "bundle" nodejs code with the API proxy any longer. I suggest that you build and run your nodejs app in Cloud Run. It's easy to do, and it will perform well. Keep the API proxy configuration in Apigee.

I am not an expert on Cloud Run, but for nodejs apps, deploying your code to cloud run could be as simple as:

 

gcloud components update

REGION=us-west1
gcloud config set run/region $REGION

PROJECT_ID=my-gcp-project-1
gcloud config set core/project $PROJECT_ID

gcloud run deploy my-nodejs-app --source . 

 

This is from https://cloud.google.com/run/docs/setup . This works for me, for all of my apps.

The output of that will give you an endpoint. You can then connect from your Apigee X proxy into that cloud run endpoint, using Google Authentication. You'll need to grant the role roles/run.invoker to the service account , to allow it to invoke that cloud run service. More on that here. (Though the endpoint is public it will be restricted from outside invocation.)

@dchiesa1 Thanks for the Quick response. Can I call Apigee X api proxy url from nodejs code using cloudRun...? In my existing Apigee Edge account I used Hosted Target for proxy chaining(Calling another Api proxy internally). 

Yes , in general, you can call from CloudRun-hosted logic to Apigee-managed endpoints.  CloudRun assets run within your Google Cloud VPC, and because of that it is possible for you, or your network administrators, to introduce network restrictions that would prevent this connectivity.  But in general, It is possible.