Configuring Pub/Sub for Restful API - google-cloud-platform

I am trying to configure a pub/sub subscription to receive messages from a public Restful API. I am unable to locate any such thing in the tutorials or the google docs. Is there any tutorial with the steps needed anywhere?

This is easy to do if you understand Google Cloud, Authentication and the documentation.
This Cloud Pub/Sub API documentation is here. If you are just getting started with Google Cloud, this documentation assumes that you already know the basics.
The service account authentication is here.
I would start by first getting comfortable with Pub/Sub in your favorite language using a library. Start here.

Related

Google Analytics and Google Cloud - what is the. link

We are exploring Google Analytics / Reporting APIs and have noticed that it forwards to the screen where we are asked to create/associate a project in google cloud interface and enable APIs.
We are struggling to understand the link between GA and Google Cloud. So there are things below we are trying to determine.
How is the Google project linked to the clients GA account. Do I need to somehow link it in the project screen.
Once in the Google project screen (Google Cloud Platform) how do I set up the API and get the OAuth and token needed to the API Call
In google cloud analytics dashboard what data will I see. Is it only Google Cloud services or actual GA Data.
GA and Google Cloud APIs how will they be connected. How will GA use these Credentials and both will be linked. If support GA is tracking my website usage or access data. What will enablement of these APIs do in that regard. There is no specific example showing that.
Any advice you can provide would really help me.
thanks,
Aakash

Does google cloud have something like "lambda#edge origin response"

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.

Authenticating Cloud Functions URLs for Google Pubsub push in same project

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.

How to invoke gcloud CLI or API command within Dialogflow fulfillment webhook code?

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

Google Cloud Functions: Pub/Sub vs Rest triggering

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)