SPEAKER: Hello, and welcome to this episode of the Apigee
Accelerator series.
In this video, we'll be demonstrating
how to create and send custom log messages from an Apigee API
proxy to Google Cloud login.
In this example, our simple proxy
will be sending regular API traffic to the backend.
One important aspect is that it will be using Apigee's Google
Authentication feature that allows a given API
proxy to easily authenticate to any Google Cloud service using
the credentials of a service account.
Let's get started.
In order to run the sample, you need
the following prerequisites-- an active Apigee X
instance configured for receiving
external traffic, the following tools in your terminal,
and also permissions for creating service accounts,
setting its IAM permissions, and creating and deploying
API proxies.
For this video, we'll be using the CloudShell tutorial
so we can quickly get started, and all the tools
are already preconfigured.
OK, now that we are in the Google CloudShell environment,
we can follow along with the step-by-step instructions
on the right-hand side.
First, let's make sure we are logged
in with the correct account.
All right, so I'll just cd into the cloud-logging directory.
The next step is customizing the env.sh file
with the required information.
We can click here and add our information, such as our Apigee
project, the host alias, the environment
that we need for executing this sample.
Remember to save your file.
Let's source it, and then we can get started.
The next step is just executing the deploy script.
This deploy script will deploy the API proxy, the service
account, set its permissions, and then we
can see how it works.
It can take a few moments.
All right, now that the script is finally over,
let's take the next steps.
First, let's generate a few simple API calls.
And next, let's try to read the log messages
that these calls generated from Google Cloud Logging using
the gcloud CLI tool.
Let's read it again.
There you go.
Now, let's see more details of what's configured in Apigee.
Let's select the API proxy we just created.
The first thing to notice is that this API proxy
is deployed to have the permissions of a service
account that the script also created.
So we can see it here.
Now, click the Develop tab, and let's see
what this proxy is all about.
If you see over here, it has just
a single message logging policy executing the PostClientFlow.
This is a special flow that is executed after the response is
sent to the client.
It's very useful to not add any latency
in issuing this log message.
That's the policy itself.
In the policy, see that we set the LogName
we want to use, some system variables here,
organization, environment, some information about the request
itself, the response code, content,
and even a literal value.
To finalize, let's just double-check the service
account that the script created.
Let me just refresh.
So here it is with the Logs Writer permission.
And last but not least, let's check our log messages
in the UI of Cloud Logging, of course.
So here we can see in more detail
the log messages we sent.
To finalize, back to CloudShell--
please rate this tutorial.
And if you want to clean up, just
execute the clean-up script.
We hope you found this sample useful.
And if you enjoyed the video, please
hit the Like button below.
You can subscribe to our channel to see
more videos in this series.
If you have any questions, please post them
in the Apigee community.
Thank you so much for watching.