I have HTTP Cloud Function and I would like to use it as the Google PubSub Push endpoint. Cloud Function, Topic and Subscriber all are in the same project.
As per the link I can use something like /_ah/push-handlers/.* with the Cloud Function URL and it should work but I am unable to find any example of how to use this with Cloud Function.
I already know the other way i.e. I need to do Site Verification & Domain Verification but to me this sounds really stupid when both the Cloud Function and PubSub are in the same project.
Can some one put some light on this. Any help will be appreciated.
Thanks!!!
/_ah/push-handlers/.* is only a requirement for App Engine, not for Cloud Functions. As the documentation says:
The mechanism is similar for Cloud Functions, but does not require any particular path.
Related
There is an application already pushing to Google PubSub topic T1 in a different project and I would like to have the Google Cloud function triggered by the publishing on T1. I read the official document https://cloud.google.com/functions/docs/calling/pubsub that it is not possible to trigger cross-project and tried creating the cloud function too from the GCP console but do not see the topics from other projects even though I have access to those projects
I am looking for alternatives. Is it possible to achieve it in a different way?
The trick is to use HTTP communication and not native event communication. I mean you have to change your Background functions (that you plug on a PubSub topic) in a HTTP function.
By doing that, you also have to create a PubSub push subscription on your PubSub topic and to add the Cloud Functions HTTP URL as target.
Don't forget to configure the security part to allow only secure and authenticated communication between PubSub and your Function.
Alternatively, you can follow Piotr advice (in comment) and use other HTTP oriented product, like Cloud RUn. But the principle is still the same: PubSub push subscription is the key!
So we have made a google cloud function with an HTTP trigger.
My aim is not to include firebase in this project.
How can I use my custom domain to connect to google cloud function using cloud DNS or something equivalent?
I already tried using a CNAME record but it didn't work as expected.
The Aim is to avoid CROS when we invoke it using Javascript/JQuery.
Thanks in advance.
The only way to map a custom domain to your HTTP/S triggered Cloud Functions is by using Firebase Hosting. There is no way to do so without using Firebase.
I belive #Frank is right, the way to go here is to use Firebase. But to improve GCP product or to have this feature in future, I would recommend creating a feature requests to support CNAME, you can create it under Compute --> Create new Cloud Functions issue or you could pick any of the more relevant link
Aws let setup lambda#edge function executed after a response is received from the origin(see picture bellow), can I do it with GCP?
UPDATE
This can be done now with the Cloud Functions service in Google Cloud Platform, as stated in the official documentation 1.
"Cloud Functions allows you to trigger your code from Google Cloud, Firebase, and Google Assistant, or call it directly from any web, mobile, or backend application via HTTP."
In this document can find the features comparison of AWS and Azure with matching features in GCP, including the one just mentioned of GCP Cloud Run matching AWS Lambda 2.
Finally, can find documentation on how to write Cloud Functions, the different programming languages used, and examples for the different usages here 3.
I would like to know, how to invoke gcloud CLI or API command from Dialogflow fulfillment webhook code.
Here's an example objective: I would like to trigger the creation of Google cloud compute engine, from the Google actions invocation. So I'll be writing a dialogflow fulfillment to achieve the compute engine creation.
I've researched the Google Dialogflow documentation and it does not have much detail about invoking the "gcloud" command in Fulfillment webhook code.
So it would be good to know,
Is there any dialogflow libraries can be used to invoke gcloud CLI or API?
How to handle the those requests within dialogflow fulfillment code?
Are these details are available in a documentation? if yes, please share the URL.
This question would be helpful to developers, who are seeking for similar information on developing Google actions using Dialogflow.
I'm not sure what you mean by gcloud CLI or API, you may need to be more specific as to what you'd like to achieve.
But in case I understand correctly, you'd like to trigger some gcloud API functions. If that's the case; Dialogflow fulfillment (usually) runs o Firebase Cloud Functions. If you're using Firebase for your deployment, you can use gcloud node.js client library to use Google Cloud Platform services.
If you're using your own fulfillment server, you may use the appropriate gcloud client library for that as well.
Q1. Is there any dialogflow libraries can be used to invoke gcloud CLI or API?
Answer:
Google has node.js SDK libraries, that can be imported into Dialogflow webhook code.
So, the creation of Google cloud compute resources are possible through the nodejs library “google-cloud/compute”
Q2. How to handle the those requests within dialogflow fulfillment code?
Answer:
Perform the below changes in the Dialogflow webhook code
In package.json add the compute library in dependencies section,
"dependencies": {
"actions-on-google": "^2.2.0",
….
….
"#google-cloud/compute": "^0.12.0"
}
In index.js file utilize the compute library
// Imports the Google Cloud client library
const Compute = require('#google-cloud/compute');
// Creates a client
const compute = new Compute();
Therefore the “compute” object created above can be used to implement all the functionalities related to Google Cloud Compute resource.
Q3. Are these details are available in a documentation? if yes, please share the URL.
Answer:
Refer Google Cloud Compute Library Documentation Here
Refer Google Cloud Compute Library Documentation for creating compute resource
Is Pub/Sub significantly faster way of communicating between, say, Kubernetes Engine (GKE) api server and a Cloud Function (GCF)?
Is it possible to use Pub/Sub to have such communication between GKE from one Google Cloud Project and GCF from another Google Cloud Project?
What is the way to communicate with Cloud Functions from another Google Cloud Project with low latency?
I think a global answer will clarify your questions. For this particular case, there are two ways to trigger a Google Cloud Function (GCF). You can directly make an HTTP request or you can subscribe the GCF to a topic by using Pub/Sub [https://cloud.google.com/functions/docs/calling ].
If your requests are occasional, an HTTP request will be faster because you don't need an intermediary. If that's not the case, then the Pub/Sub subscription queues the messages and ensures the delivery by retrying them until it receives confirmation.
To communicate between Google Kubernetes Engine (GKE) from one Google Cloud Project and Google Cloud Function (GCF) to another Google Cloud Project you can use either option. Trigger the GCF by the HTTP request directly or do it by publishing the message. When publishing, specify the project where you are sending it and the desirable topic in that project.
Also you need to give the proper permission to the service account to access from one project to the other:
For Pub/Sub https://cloud.google.com/pubsub/docs/authentication
For HTTP request
https://cloud.google.com/solutions/authentication-in-http-cloud-functions.
Google Cloud Function HTTP triggers documentation here: https://cloud.google.com/functions/docs/calling/http
Pub/Sub documentation here:
https://cloud.google.com/pubsub/docs/reference/libraries (you can
access to GitHub by the links in the code and see functions examples
for each language)