[MUSIC PLAYING]
THOMAS BOULDIN: Woo!
JEN PERSON: Oh.
THOMAS BOULDIN: Hey!
JEN PERSON: Oh, thank God.
THOMAS BOULDIN: How's it going?
JEN PERSON: You're here.
I was getting worried for a minute.
THOMAS BOULDIN: Oh, come on.
I'd never let you down.
JEN PERSON: Ready to do a show?
THOMAS BOULDIN: I'm pumped.
JEN PERSON: Let's do it.
How's it going, Firebase developers?
Welcome to another episode of "AskFirebase," the show where
we answer your burning Firebase questions I'm Jen Person,
and today I am joined by a very special guest who
works on a product that is really near
and dear to my heart, Thomas Bouldin.
So Thomas, what is it that you do here?
THOMAS BOULDIN: So I work on the project Cloud Functions
for Firebase.
It's basically what I've been doing my entire time here
at Firebase.
It was started by trying to get the real-time database
connected to this new upcoming thing called Cloud Functions.
We kept on kind of working on the user experience.
And it ended up spinning into a whole set of tools
to make Cloud Functions really fit in the Firebase developer
experience.
JEN PERSON: Hm.
THOMAS BOULDIN: So started with that, and now I focus also
on trying to make sure we get you the best
events for your Cloud Functions, that they are reliable, quick,
and all of them that you need.
JEN PERSON: Great.
We get a lot of questions about Cloud Functions for Firebase.
So that's what we're going to look at today, if that's
all right with you.
THOMAS BOULDIN: Of course.
JEN PERSON: All right.
Let's do it.
THOMAS BOULDIN: Good.
We have a question from Arangates.
Ask Firebase-- how can we use TensorFlowJS
with Firebase functions?
JEN PERSON: Cloud Functions have a lot of great use
cases for something that you want to spin up quickly
and run and then shut down quickly.
TensorFlowJS, if you're talking about large data sets
that you're going to be running on,
is not a very good use case for Cloud Functions.
Even though you can extend the life of Cloud Functions-- still
not a very good use case for that.
Now we will link to some information about TensorFlow,
if you want some options, some Google options for how
you can use TensorFlow and how that can still
run some data sets and be connected
to Firebase through your own server using the Admin SDK.
That's definitely an option.
This next question was for me.
But I'm going to pass it off for you, so--
CutikoLive wants to know--
I have a hashtag question about Functions.
Can we use export default and import
ES6 in our functions projects?
THOMAS BOULDIN: Oh, man.
So this is kind of a halfway yes answer.
So the version of Node.js that we run in Cloud Functions
does not yet support the ES6 style
syntax of import and export.
On the other hand, we do support TypeScript, which gives you
these features ahead of time.
But what's interesting is that ES6 default exports are not
actually that smart.
They're just literally an export called default.
So you could do this, but you might actually
end up with some slightly weird results
when you use the entirety of the Firebase toolchain.
So if you use the G Cloud command line
tools, the ones that Google Cloud platform uses,
the name of your export and the name of your function
are totally separate.
And so you could name it a very friendly name if you use
[INAUDIBLE].
With Firebase, we tried to just simplify the use case
that most people fall into.
And so we automatically name your Cloud Function,
whatever the export name is.
So technically speaking, yes, you
can use the default export, especially
if you use TypeScript or in the future we upgrade
to the next version of Node.js.
But your function is going to be called default, which
probably isn't that useful.
JEN PERSON: Oh, yeah!
Yeah, this one-- I was, like, wow,
that is actually a really good question.
You feel good about it?
Want to do it?
THOMAS BOULDIN: Sure, yeah.
JEN PERSON: Let's take a crack at it.
This next developer wants to know
when I go to the Cloud Functions UI,
I can view all logs from a execution by an execution ID.
Is there a way to get this execution ID in the currently
executing function, so I can send this ID in an HTTP error
response for debugging?
THOMAS BOULDIN: So this is a great question.
And frankly, thank you for asking it.
Because it kind of helps raise awareness of something
that we could do better.
So in the HTTP functions, this is actually a header.
So if you look at the request.header section
in your HTTP function, there's actually a field--
I think the header is called a function execution ID.
And this is the same one that shows up in the logs.
We're not currently doing what we should do to afford it
inside the event object.
And so thanks to this question, we've
actually started raising the idea internally
about how we should start exposing this
so that you can do use cases like this.
JEN PERSON: Yeah.
This is a great time to bring up, then,
when you come across something that you notice is missing,
make sure you file a feature request.
We really appreciate it.
This is how we learn what is important to our developers.
THOMAS BOULDIN: Yeah.
In the meantime, though, for these event-based functions--
so for example, if you're handling
a change in Google Cloud Storage or the real-time database--
there's also something called the event ID.
Now you can use this almost instead of the execution ID.
These are very related and almost subtly different
concepts.
When you call an HTTP function, it will either work or it
won't.
It happens one time, and that's it.
With event-based functions, you can turn on retries.
And so if you want something to be-- we call it item potent,
so it doesn't matter where it failed,
it will keep on getting to the final goal when you do
retries--
you should use event ID for this.
And you can also use it to log it and help
find your logs and any error response.
But if you actually need to know this exact function run,
the way that we see them in the logs,
that's the header that we're going
to start looking at forwarding.
JEN PERSON: Cool.
THOMAS BOULDIN: This is all one question?
JEN PERSON: Yeah.
This next question comes from Jaye on Stack Overflow.
And Jaye's wondering about, in their Firebaserc file,
I provided two Firebase databases,
one that they're using for dev and one for production.
We can show that that looks like.
So when they're deploying to production,
they just run Firebase use production,
deploy only functions.
Problem is, they're also using Cloud Storage in one
of the Cloud Functions.
So they have two different serviceaccountkey.json files,
which looks like this.
[INAUDIBLE]
THOMAS BOULDIN: [LAUGHS]
JEN PERSON: So they want to know how do I automatically switch
to another serviceaccountkey.json file
when I switch to another database via Firebase?
THOMAS BOULDIN: The first part of this answer
is make sure you actually need to do this.
So Google SDKs do a lot of really cool tricks
behind the scenes so that you can automatically
initialize them when you're running
inside Google infrastructure.
So this technology is called Google application default
credentials.
It's a really cool thing to learn more about.
And so unless you are specifically
using the SDK to create a download URL,
you actually don't need a certificate file at all.
You can just initialize all the at Google Cloud
SDKs with just open paren, close paren, and it works.
And in fact, with Google Cloud Storage,
we go a little bit further.
And if you use the Firebase Admin SDK,
not only will we give you the right credentials,
but when you say admin.storage, we know your default bucket.
If you do intend to use the Google Cloud Storage
SDK as it is, alone, like I said,
you can use the Google application default credentials
to initialize automatically.
You will need to know your bucket name in order
to actually do anything with that.
And we've actually deployed the default bucket name
with your Cloud Function.
So in functions.config .firebase.storagebucket,
I believe.
JEN PERSON: Hm.
Nice.
THOMAS BOULDIN: So that, of course, is documented.
So just go check out the Firebase docs
and light up those keys.
On the other hand, if you do need that one API,
the create public URL--
JEN PERSON: Get signed URL--
THOMAS BOULDIN: --or say-- yeah, there we go.
[LAUGHS] Clearly you've been answering these questions a lot
more recently than I have.
JEN PERSON: Yeah.
This one comes up quite a bit.
THOMAS BOULDIN: Aw.
I really want to get rid of this limit.
But if you do need to use the certificate file for that one
API, what I recommend you do is download your certificate
and put it in the runtime config.
You can put it in the same key for both your dev
product and your prod project.
That way the code will work seamlessly on dev
or prod and use the right credentials.
JEN PERSON: Cool.
Yeah.
And plus, you got to hide that-- you're
going to want to hide that key anyway.
THOMAS BOULDIN: Yeah.
JEN PERSON: There you go.
Thanks so much for coming on and answering some questions
about Cloud Functions for Firebase.
Remember if you have any questions about Cloud Functions
or any other Firebase features, be
sure to list them on social media
with the hashtag #AskFirebase, and you may see them
on a future episode.
Be sure to subscribe to the Firebase channel,
so you can check out new episodes of "AskFirebase"
as well as "MeetFirebase," and "Firecasts,"
and all of the special features that we have going on there.
Thanks so much for being on the show.
THOMAS BOULDIN: Of course.
[INAUDIBLE]
JEN PERSON: And thank all of you for watching.
See you on a future episode.
THOMAS BOULDIN: I am 10 times more famous
than I was five years ago, and that's still not
saying a whole lot.
[LAUGHS]