Cloud Functions with Python (FaaS) from zero to hero! | David Armendáriz | Skillshare

Playback Speed

  • 0.5x
  • 1x (Normal)
  • 1.25x
  • 1.5x
  • 2x

Cloud Functions with Python (FaaS) from zero to hero!

teacher avatar David Armendáriz, #NeverStopLearning

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Watch this class and thousands more

Get unlimited access to every class
Taught by industry leaders & working professionals
Topics include illustration, design, photography, and more

Lessons in This Class

24 Lessons (2h 17m)
    • 1. Introduction and recommendations

    • 2. Creating a project in Google Cloud

    • 3. Adding our project to GitHub

    • 4. Creating a new branch, a new virtual environment and requirements

    • 5. Committing our changes

    • 6. Writing and testing our first Cloud Function

    • 7. Passing multiple arguments and passing JSON to our Cloud Function

    • 8. Deploying our first Cloud Function to GCP

    • 9. Using Sendgrid to write our second Cloud Function

    • 10. Testing our Sendgrid Cloud Function

    • 11. Adding basic securities to our Cloud Function

    • 12. Improving the way we get the Bearer token

    • 13. Deploying our Sendgrid Cloud Function with environment variables

    • 14. Understanding why CORS is blocking our Cloud Functions

    • 15. Committing our changes before we continue

    • 16. Adding pycache to .gitignore

    • 17. Adding CORS to our Cloud Functions

    • 18. Creating a Firestore database and adding Google credentials to our project

    • 19. Writing and testing a Cloud Function with the Firebase SDK for Python

    • 20. Deploying our Cloud Function to GCP

    • 21. Committing our changes

    • 22. Scheduling our Cloud Functions with Google Scheduler

    • 23. Deleting Cloud Functions

    • 24. Conclusion

  • --
  • Beginner level
  • Intermediate level
  • Advanced level
  • All levels
  • Beg/Int level
  • Int/Adv level

Community Generated

The level is determined by a majority opinion of students who have reviewed this class. The teacher's recommendation is shown until at least 5 student responses are collected.





About This Class


Cloud Functions are one of the most useful things you can learn this year! Have you heard of APIs? Well, it can be difficult to deploy them and actually use them if you don’t have experience in this topic, but fortunately, Cloud Functions help us to construct and deploy APIs and execute backend code without having to worry about scaling or managing our servers.

And furthermore, we are going to use one of the simplest yet most powerful programming languages of all times: Python!

It can’t get better.

In this crash course, you will learn lots of things like:

Implement Google Cloud Functions in Python

Use an environment, version control system (Git & Github) and adding meaningful documentation (Markdown)

Test Cloud Functions locally

Deploy Cloud Functions from the terminal

Test deployed Cloud Functions with Postman

Add basic securities (Bearer token) to Cloud Functions

Manage CORS to Cloud Functions to fetch them from the Browser

Schedule Cloud Functions

Delete Cloud Functions

Meet Your Teacher

Teacher Profile Image

David Armendáriz



Hi! I am David Armendáriz and I am an ecuadorian mathematician. I like everything related to Data Science and also I like to apply my knowledge in this topic to software.

See full profile

Class Ratings

Expectations Met?
  • Exceeded!
  • Yes
  • Somewhat
  • Not really
Reviews Archive

In October 2018, we updated our review system to improve the way we collect feedback. Below are the reviews written before that update.

Why Join Skillshare?

Take award-winning Skillshare Original Classes

Each class has short lessons, hands-on projects

Your membership supports Skillshare teachers

Learn From Anywhere

Take classes on the go with the Skillshare app. Stream or download to watch on the plane, the subway, or wherever you learn best.


1. Introduction and recommendations: Hi. My name is David Letterman. Daddy's I am a mathematician and a data scientist. On in this course, I'm going to teach you Google Cloud functions with Python. Okay, so what you learned in this course is to implement the Google Cloud functions with python with best practices. By using a virtual environment and creating a meaningful documentation, we're going to test cloud function before deploying them. We're going to deploy them to the cloud, obviously, using the pharmacy lie. This means the terminal we're going to test already deployed Glad functions with the most popular software for testing Ap Eyes Gold Postman. We're going to add a basic securities to blood functions and we're going to add course to use glad functions from the browser. If you don't know what this means right now, don't worry. I'll explain it later. We're also going toe learn how to schedule blood functions so they trigger automatically according to a schedule. Okay, So what are Google Cloud functions? Their part off F A s functions as a service. So Amazon has also insert. It's like this. It's called a W s Lambda functions. Maybe you've heard that, but the point is that that functions lead, you automatically run back and cold in response to events and https requests. Okay, so what do I mean with friends? Google Cloud has the service called Fire Base and, for example, infirmities. You haven't no SQL database. Gold first or on event can be something like obtaining a documenting these database or deleting it are these kinds of things. So Google Cloud functions can react to these kinds of events from fire base. So your code is a stored in Google's cloud and runs in a managed environment. This means that didn't have to worry about managing or scaling your own server. So if you have lots and lots of requests, you don't have to worry because Google is in charge off, creating more instances to handle off these requests. Okay, So before I continue with the next lesson, I will suggest you one thing you can use Lennox or Mac O s. This is because in Windows it's very Massey working with a terminal. And if you want to become a really good developer, well, it's no harm if you use Lennox or Mac Os. I know Mac Os is very expensive that Lennox is free. You can use a bull to you can use ah means or Federer. I don't know, but it's a lot easier to work with these operating systems than using windows. So, yeah, this is everything I can tell you that you can see I am using here, oval of Do I have my eternal here on? Well, the only these advantages I don't have. Maybe the office package. But as you can see, everything is in the cloud so I can use power point in the browser. So I don't have to worry about doing presentations and in a wound. So that's everything I can tell you. See you in the next lesson. 2. Creating a project in Google Cloud: Hi. So before we implement Google God functions, we will need to set a project in the Google Cloud platform. So obviously we will need a Google account. So if you don't have a Google account just created, it's very, very easy. Then goto cloud that Google that come a slash free on bond, we will land on this page. That is the description off the Google Cloud platform free tire. So generally all of these cloud services have a free tire on Google is not far behind. They will give us $300 of free credit. That will be that will be valid for the next 12 months. I'm also here. We have free brother. So these free products are here. For example, if we go ahead to the glad functions, we will have two million invocations per month free. So this camel, um additionally to your $300 of free Craddick. So if you invoke more than two million times your cloud functions, then you will be charged on those $300. But I don't think we will be invoking our todd functions to medium times. Eso these is a lot. Okay, So, in order to get access to our free proud products plus or 300 free credit weekly. Come here. Get started for free on. Then you will be asked to put your country minus Ecuador and to accept the terms of service . Also, you get specified here that you have $300 off free credit on no other payment will be executed after your free trial ends. So you accept Here you click on continue I want because that expiation have information about my account and about my billing information. But you have to click on continue feeling your billing information and then you will have access to the free breads that are specified here. Last your $300 of free credit. Okay, so after you do that, you will have taxes to the fire based council. So you goto Carcelle that fire base that Google that come and you will have access to this dashboard and also to this dash were here. That is the Google Cloud Platform Council. So in order to access here, you need to type council that glad that Google does. Come on. Well, we can create our project from here or from here They're connected. So I will leave from here from that fire base council. So you click on at Project on, Enter the name of your project, so I'm going to name it. Blood functions, of course. And click on. Continue. You can enable Google Analytics for your firebase project. I won't enable it. I'm going to create the project right away. So we have to wait a both meanings in order for our Bridget to be created and after it is created, we're going to also see it here in the all top here. Glad function scores. It's already there. So glad function scores on your new project is ready Weekly going. Continue on. We have access to these new dash word. So as you can see here we have functions. So well, we wait for the space to load on. We can get it started. And we can also bleak here on the Google glass Blood Pro Consul and asked on search here Fun four functions God functions on. Well, we're going to explore more of these, um, in the later lesson, But just now you have your break it created on. Now we're ready to implement our Google cloud. So functions So see you on the next lesson 3. Adding our project to GitHub: hi and welcome back. So, in the first lesson off this course, I told you that we were going to implement Google Glad functions using best practices. So this means that we're not just going to write Google, glad functions on, deploy them to the blood like crazy people, But we're going to actually use version control system. This means we're going to use git and get hub. We're going to add meaningful documentation. We're going to use a virtual environment, and we're going toe. Also use on integrated development environment. And I ve so for these last one, we have several options I am going to use throughout this course by charm, bro. Uh, this is a paid version off by charm. So you can download this for free the free version of by term. But I have the license off by Trump Rose. I'm going to use it. There is another option called the V s code. It is also very famous, and it is also free. So feel free to choose whatever you feel more comfortable. Um well, OK, so the first thing we're going to use we're going to do is to create a folder. You can create it in your desktop. I'm going to name it repositories. And here I'm going to grade in your folder called Google Google Cloud Functions Course. Okay, so now I'm going to open these folder from by charm, So lead see where it is. It is here, on here. Okay, so now buy charm open and my folder on the first thing we're going to do east to add a reading me file. So air every project should have a read me file so other people can understand what you're doing. So let's Redlich here at new file on name it. Read me, um dot MD So this extension and the s stands for marked down, So documentation usually is ridden in marked down my gullet. We can just symbols toe Uh, right. The beautiful documentation. For example, if I write hashtag Google Cloud functions course, then these big title will appear here. So this is like the h one, uh, in html. If I had to hash stocks, then I will have also title bad. Ah, with ah with a fund with his mother fund. Ok, so starting a project. And here I can add instructions, for example to start a new project in Google Cloud we can go Ah, to the And here I can add a link Firebase coastal on our dealing https double slash five ways that I mean console that fire base that Google that come or created from, um, Guru Cloud that form council and we d link EADS almost identical to this one that instead off fire base we use here. Blowout. Okay, So anyone who is reading your documentation says, Oh, I need to start a new project in Google Cloud. I can click on this link and I will be able to create it from here, or I will be able to create it from here so that that's very nice to have on also here we're going to create what's goal? A did ignore file. So we're going to use a version control system and I'm going to tell you, Ah, what's the utility off these getting nor file later? First, let's go to get hub here, The world's leading software development, Lavilla. Um, if you didn't have an account just created, it's very easy. And if you already have an account and just trying going to signing and I'm going to create in your rebel here like leak on this bottom. I'm going to give you the name Google Cloud Function scores. I'm going to make make it public. I'm going to say here, here is the code for the Google Cloud functions scores made by Davey, Adam and Ice. Okay, so pretty descriptive. And here I have, um, deceptions initialized this repository with a read me. I'm not going to check it because we have already created our own read me file on. I didn't get ignore file. Well, no, because we already have a getting nor file and other license. Okay? No. So we just created Okay, so here we have some, um, instructions. But just ignore these. I'm going to teach you how to add our coat to these ripple. Um, from scratch. OK, so here, in my charm, we have deception terminal. So it's the terminal from Wu Little. In my case, I'll here. I'm going to right the followin common. Get in it. So on empty git repository was created in these, uh, directory on. The next thing I'm going to do is to copy this line only this line copy and paste it here, Get remote at origin. So this is to add this repository to these directories. So, as you can see here, the's file is in red, these violent souls and red. Let's see what happened with this command called Get the stats. So it says we are on the branch, Master, there are no commits yet. And we have these untracked files. So we have, get ignore. We have these idea territory which is hidden on this. Read me that empty file. So this the idea directory, we can see if we tied l s minus a. So as you can see, it is there. But it is hidden just as these, um, these folder called get so we can ignore this file because these this is folder I mean, because this folder is not part off our project is something that comes along with by charm . So in order to ignore these, um, these folder we added here the idea is lash. And then let's get status again. So, as you can see now, these Doug idea folder is not going to be tracked, So a dread files are only get, ignore and read me. So that's the utility of these getting nor file to ignore files that won't be tracked in get. So the next thing we're going to do is to get at um well, before doing this. If this is the first time you're using get, then you have to do the following configuration. Get config minus minus global. And here you serve that email and you specify your email. So mine is thes one. You have to use the same email you provided in your get Have a count on give gone fiqh minus minus level. User That name, Um my niece David. And then we're going to do the following command. So get at the dot means that we're going to track all of these files. So ignore and read me. We can do this, get, ignore and read me. Ah, that MD that this is an efficient way. If we have lots off files were just going to want to do this, get ad that So now we have to commit these changes, so I'm going to say first commit and then we are going to do. We're going to copy this coming here. Get Bush minus you, Origin Master. So let's just copy Bassitt. Um, here it is. So now we're tracking the master branch. So let's refresh this page here. So was you can see I have my getting nor file, which has this idea. We have our read me, which is here. So if you go to my rep Oh, you're going to find these These rid me? Um well, we have one branch, which is master one. Commit on. That's all you have hearing it. So one thing we have to be very careful. So this master branch is usually used only for production Goat. So if you have a very large company like Facebook on they have a rebel where the goat of Facebook is hosted, they're not going to modify code here in the master branch because this is only for production. So if you mess around with a code in a master branch, then maybe all of the Facebook will be shut down globally, and that will be a very big problem. So in the next lesson, I'm going to teach you how to create another branch. So we working a developed branch? Um, the Jews, Some more interesting things. So see you in the next lesson. 4. Creating a new branch, a new virtual environment and requirements: Hi and welcome back. So in the last lesson, I told you that working on the master branch is not a good idea because here we usually have production. Goat. I mean go. That is very important because it is working for the production back in for the production for intent. I don't know. So touching code in the master branch is not a good idea unless you have authorization. If you have made a full request with which is like reviewing your code before merging your changes to the master branch. So Master Branch is very dedicate. I we shall not touch it, so I know this is of course, but it is a good idea if you get accustomed to these ideas from the beginning. So in order to great another branch here in the terminal, we're going to say good branch, develop the developed huggy. So if I least all of the local branches I have here, you can see that I have created these developed branch and we're currently working in these master branch. So, in order to work in the developed branch, we say get check out develop. Okay, so now we are in the develop branch. Okay, So in order to delete these ranch, you first go to the master wrench and say, get branch minus capital t develop. So I deleted these ranch develop locally. Um, that See again, the list of ranches I ah, I have only now the master brunch. So there is a comment also for creating the new branch while at the same time switch into it and it is give check out minus v develop. So let's see. Now I created again the developed branch and I switch it, and to it automatically with this command, get take out minus b developed. So from now, one, we are going to only work on that developed brunch. After I finish making this course, I'm going to merch all of the changes of the DiBella branch into the master branch. But that will be a work for me, so don't worry. Okay, so that's the first thing I wanted to tell you. The second thing I want to tell you is that we're going to use a python virtual environment . So when I was told Ubundu in my computer, I had at by conversion already installed. So let's see what What version is, uh I thought three minus V. Okay, so it's by 33 that six that night. Because I also have Brighton too, I think. Okay. So sorry. I suppose I am working here with a certain library in ghoul in these project called Google . Glad Function Scores. So suppose I want to work with these package called pandas. Okay, so I execute this command and the pandas package is going to be installed in my Bytom version here. OK, but now suppose that I have another project that uses again pandas, but another version. So when I do this, it's going to be installed The latest version and this. But suppose that these other project works with a an older version of the bandits package. So this project Google Cloud Function scores will work fine because it's going to use the latest version of pundits. But the other project will crash because it only works with an older version off pandas. So you see, that's a problem, because ah, these uses the latest version. The other project uses an older version and yell, the other is going to crash. This is not going to crash If we want the other break, not to crash. Then we have to downgrade pandas version. But then this is going to crash because we downgraded that the Bendis version. So it's a big, big problem. Fortunately, we have a solution for it on its gold virtual environment. So virtual environments is like having your own python version inside a specific product so we can add these to the documentation creating a virtual environment. So another person that is a senior code is going to say, Oh, here's the coat in order to create a virtual government. So the first thing you have to do is to install the Bytom three events. So first we have to do these first we have still and we cannot in line code with this back ticks on, say, iPhone three with their following come in and here I'm going to add three bags back ticks and say pseudo up install um, Bytom three them. So, yes, you can say this is in line. Coat on. This is a bloke off coat. So if I installed this python, three of em, it is going to say here that it is already installed in my computer, but maybe you don't have install it in your computer. So remember these this is going to change for my cause and for Windows, I'm going to give you the specific commands for those operating systems. But if you're using linens on global toe specifically, then this command is going to work. Fine. So after doing this, I want to add something to that getting or so I'm going to add these new folder called VF to the Getting your on. Then I'm going to say by the three minus M v f is the command agree? The virtual environment and them is going also to be the name off the folder containing the new Python interpreter. So I don't think this takes too much time. Yeah, in fact, it waas created immediately. So let's just load over on disk. And now I have these folder Khaled VF Ah, here in my branch. So let's see him get status. And as you can see, that folder was not added to the to the changes because we put it in the get ignore. So we can also Well, we can also add that gunman we wrote here. So then we execute the following comment. Um, we say here by from three minus m them. Okay, So, um, now we have to activate these very environment. And in order to do that, I do the following source there being I've debate. So now you can see that I have here them. And this is This means that now my virtual environment is activated so we can add this to the documentation to activate the virtual environment we do on. We had the co's, which is source them. Bean activate. Okay, so now the next thing we're going to do is to have a filed gold requirements, requirements that the eggs on this file Well, you can add here at this file is going to have all off the packages that are going to be Onley in these virtual environment. So, for example, we're going to meet this package school functions framework. Okay, So, in order to install these, um, the package is specified in these requirements that txt file we do the following a deep install Miners are requirements that the extreme So also we cannot that to them documentation in order to have new back adjust to our new virtual environment, we create a file gold requirements the dick steam and execute the following comment on We had tree back ticks and say, Babe installed minus our requirements that 60. So these you need to do to execute this comment on Lee when these v e n v is here. So the packages where, um and installed but here, it says failed building will for battles. So in order to ah mm, fix that. You say deep install wheel. So this is 11 time thing you have to do, and then Okay, so everything now is fixed. Okay. So you can see here in settings, for example, settings. Okay, so Okay, so here you can see in Project Project interpreter on here. Let's actually these interpreter and here you legal existing environment. So you click. OK, I know you have these packages. You see, these are the packages that are Onley installed in your virtual environment. So you can see here we have our functions framework and these other were installed with, for example, wheel on other were installed automatic so we can apply. Um, okay, on now we have everything. Free bird in order to grade our Google. Glad functions with Pfeiffer. So see you in the next lesson. 5. Committing our changes: Okay, so last time we didn't commit our changes. So in this video, we're going just to do that. So we want to commit or we want to track all of those files. Um, get ignore, rid me and requirements the 60. So we get at dot Now we write, get commit minus sam on the meaningful message, such as added a virtual environment, um added a requirement that txt filed to manage our dependencies a modified read me that m read meat that empty and added them to get ignore. Okay, so that's, uh, pretty descriptive message, and then we do get bush. Okay. So as it is the first time we're pushing to these branch, then we have to follow this command. Get bush minus minus. Said upstream origin develop. Um, that's all. OK, so now if we go to get hub and we refresh so we can go to this develop branch and see that we have to commit here on here is that committee we did 32 seconds ago that added a virtual environment added requirements that Dixie on here we can see also that changes off those files. Okay, so that's everything for this video. Just wanted to show you how you add commits to a new branch. On that you have to put descriptive messages every time you do a commit. See you in the next lesson. 6. Writing and testing our first Cloud Function: hi and welcome back. So now we're ready to implement our first Google cloud function. And in order to do this, we are going to create a new directory here. Gold Hello, world. So this will be the hello world for cloud functions inside these folder, we're going to create a python file, and it's going to be gold. Mean it needs to be called like this. You will see why later. So we're going to write a function in the world and is going It is going to receive as a parameter request here. We're going to say request arcs is equal to request the parks. So this the's thing here is going to return a dictionary or none. So in order to check if is none were going to say if request arcs and if name in request arcs, then the viable name is going to be that property name from these, um, from these dictionary request arcs else name is going to be world. And finally, we're going to return an ever stream that is going to say hello and whatever the variable name contains. Okay, So, just to understand what happening here, request arcs is going to be a dictionary. This dictionary can be empty. So if it is empty than this condition is going to be false. So everything here is going to be false. Onda variable name is going to be world. If this is not empty, then we're going to check if the property or the key name is in that dictionary. And if and that that key is in this dictionary, then the verbal name is going to be the value off that key. Okay, so now remember that we stole these functions framework package last time. Now we're going to use it to test this cloud function. This simple club function locally. So let's change directory to hello world. And here we're going to say functions framework minus minus target. Hello, world. The name off our function inside these main dot b y vel. That's why, in order for this to work, this has to be called mean. Okay, so now it says Serbian flask up. Hello. World environment production. Use a production. LaBella, where we're going to click here. This is what we are going to meet. And as you can see, it is returned in Hello world. So something I didn't tell you last time. Is that all of these Google Glad functions use flask under the hood. That's why if we go to settings and check the dependencies off our virtual environment, it it is here flask. Because when we installed these functions framework, which is a package for testing Google glad functions locally. It installed these dependency flask because these needs flask under the hood. Okay, so, um, let's see. Let's Ah, right now, As you can see, the variable name is equal to a world that means that this request arcs dictionary is empty and we're not reaching this condition. We're reaching these conditions. And that's why name is equal to world. And that's why we're seeing world here. So what do we have to do in order for these requests? Arcs a dictionary? Not to be empty. We have to Bassam arguments. And how do we pass arguments Will simply we add these question mark. We had the name off the key, which in our case is name and we say name equal to whatever you want it to be. So if you say name equal to David, then here we're going to return. Hello, David. That's because now request arcs is not empty. So this is true on the property name is in that dictionary. And so the variable name is going to be equal to the value off that key. If we change these two by thumb, let's see. Hello. Buyten s expected. But what if now this is different. So name me. It is going to return. Hello, world. Why? Because name is not now in these dictionary. It is different name from Namie. And that's why we go to these else. Aun said Name equal Toe World So that waas our first Google blood function. As you can see, it's very, very simple. We can start this with control Z on. Well, we're going to explore how to test this glad function with a software called Postman. We're going to do that in the next video. See you then 7. Passing multiple arguments and passing JSON to our Cloud Function: hi and welcome back. So, in the last lesson, I taught you how to pass arguments in the your URL. So these arguments are then processed by by phone on the scientific parables and all of these things. But I forgot you, huh? I forgot to teach you how to pass multiple arguments. So in this lesson, I'm going to teach that on. Also, they do how to pass Jason objects instead. Off arguments. So the first thing I'm going to do is to say supposed I have another argument. Gold. Last name. So we're going to check if this is in request arcs. And if it is there, they were going to say last name requests, arcs. Last name ive it is not there. Then we're going to set it to an empty stream on here. In the return statement, we're going to include that viable last name. Okay, so this is the only change we have to do in the code on. We're going to execute this command functions framework minus minus. Star get Hello, world minus minus the buck. So this is the book is going to help us to for the server to restart automatically if we make some change here in the coat so we don't have to execute the goat again. So now the and the flask op is running. So we go here, refresh. And now it's how the world and let's pass an argument. Name of Eve on another argument. Last name, arm in air. So, in order to bass multiple arguments, we have toe at these 1% a symbol on, Then write the name off the other argument and its value, obviously. So we've I read gender. Then I have these message. Hello, the with Adam. And that is so This is one way to digest cloud functions. Ah, the other way. He's We can use Boston. So this is a suffer toe test, mostly ap eyes, but we can also use is to deter blood functions. So I clicked on this at bottom and here I can enter my euro. I go being based it on, as you can see it the text, the parameters automatically. So it says, Hey, I have a permit. Er here, with a key equal to name and the value equal to the with the last name value are Amanda. So if I send my request, then obviously I will have a response. And the response is these one. Hello, David Aggrandize. But as I told you, this is not the only way to bass arguments to our glad function. We can also pass the arguments through a Jason object. So Jason stance for JavaScript object a stander object notation on It is a way. It is a universal way to pass information. For example, we can use Jason to pass information from JavaScript or from our or from rubbing rails or from no Js. I don't know from multiple ways it's very universal on. That's why it's very widely used. So in order to get information information from Jason, I'm going to declare right request. Jason is going to be equal to request that get days, Um and I'm going to say here silence equals true. So these silent equal to true means that if I don't past any days an object, then said these viable request Jason equal to numb here, we're going. We're going to to first verify if we have a request adjacent. If this is different from none, and if name is in request, Jason And if last name He's in a request, Jason. Then we're going to set name equal to request Jason. Name. So this is a dictionary, remember? And last name request. Jason. Um ing. Okay, so, no, um, as you can see now, these detective changes in that goat. So it is now reloading. So we can now use these new code so we cannot pass, um, gazing objects from a girl. But we can pass Jason objects from Boston. So here, where it's his body, we click on that. We're going to say rough. And here we're going to specify, Jason. So Jason is just like a dictionary in Bison on. We're going to say, Hey, hang here. Name equal to Let's put something different. One and last name equal do best. It's a very classic one, Pettus. And now we're going to relive these arguments here. Now, as you can see, that brands are empty because we're going now to pass those parameters, asked a Jason object. So let's send, um, let's wait again. My computer is a little bit old, and so it is a little bit slow, so let's wait patiently so it finished. And here you can see Ah, hello, 11 So we did something wrong here, and yeah, yeah, The thing is that we said here name instead of last name. So let's reload this and that sent the request again. So now it is fixed. Hello? Won best, so you can see request. Jason was a dictionary name Wasin his record. Jason. Last name Waas in this request. Jason on as these us everything here, Mr. Then we said name equal to the value off request Jason name and last name equal to the value of request. Jason. Last name on we return. Hello. Name and last name on. That is the result that is shown here. So that's how you, um, Sandy Jason objects to your cloud function. And in the next lesson, we're going to learn how to actually deploy this to Google clout. So see you in the next lesson. 8. Deploying our first Cloud Function to GCP: Hi and welcome back. Now we're ready to deploy our glad function to ghoul. So if you followed all the instructions to install the G cloud as decay, then we do the following Jake Cloud in it. And we'll, as I have already installed the the cloud as the gay and already use it. Then it's going to tell me Hey, you want to range allies this configuration or you want to create a new configuration, you will be Brompton. Another message to configure your account to lugging on all of those things. So I'm going to say just rain initialize these configuration and with my my my current email and I'm going to select the project Blood Functions. Course it's the number one. So that's a game. I select number one. Okay, so after all of these shows up, then you can dear your guns away, Andi, then Well, suppose you have another project. You were working on another project, And you you want to switch to this project so you can say G cloud projects least on. Then here is a least off your bra addict. So suppose you were in these social, blah, blah, blah, and you want to switch to your cloud function skirts. Then you have to say D cloud conflict said project and God be your project. I d basically here and updated. Robert. Now you are working on the blood functions course project. Okay, so now it's time to the blowing our first cloud function. So let's say de cloud functions that boy the name of the function. Hello, world. Remember, you have to be in the directory. Hello, world. And the, uh, the file has to be named main dot b y. Otherwise these won't work minus miners runtime by from 37 So we're specifying we want to use by some 3.7 I know we're using right now by from 3.6. But Google only supports by from 3.7. So Hugh were specifying that we're going to use that minus minus trigger H b. Okay, So this is going, um, to ask if we want on the 15 gated invocations, and we're going to say for now, Yes. In the meantime, while this glad function is being deployed, we're going to grade here More documentation, so deploying their function. Okay, So we're going to see first we have to set our project. I the with the following comment. So it is already the blood. But I'm going to continue to write the communication. Let's say geek load, Go. Fig said project your project. I d Then, um, we deploy our function with these command. We're going to say dig loud functions deploy, uh, function name. So these brackets here mean that you have to replace with your information my despite its run time. Uh, by 37 a minus minus Treeger age did it. Okay, so now that's very useful for someone who wants to deploy blood function. So he just reads all of these and knows what to do. Exactly. And as you can see here now, the function is deployed. We have available memory 250 56 megabytes. The entry point is Hello, world. This is the link. So we're going to actually, um, click on this link. I click on this link I now anyone in the world come access to this link. I'm see the head of world message. So this is extremely, extremely insecure. Why? Because remember, we have two million invocations in the month. But what if someone makes a script in order to Goldie's HDD be blood function 10 million times. Then we won't have any security on Google is going to charge us for these cloud function 10 million times on Ben, you're going to Google and say, Hey, but someone else did this on Google will going to respond and say, Well, why did you not add security to Europe? Glad function, But well, anyway, you can play with your new blood function here. You can say name that we've, um last name, sir. Last name. I mean, that is let's click enter. And as you can see, the result is just as we have in our local deaths. So that's how you deploy your glad functions. You have your run time by thens you have here the status at the diversion I d one because it's the first time we deploy our blood function. But if we make some modifications than the version, I d will be two and so on. So that's everything. Now we're going to get at everything we're going to commit. I agree and say we created a the first Google glad function, um, deployed the blood it, Then we're going to say get Boof? Um, yeah, Well, I got wrong here something. If I do this from this Hello world, then this read me is not going to be pushed in. Get help. So I have to go back to here. Hadn't do the same thing again. Eat meat. Um changed the reeve me that MD to know how to deploy. Glad function is on. Get Bush, I now. Okay, so now we have to commit its You have be one, but that's OK, so we reload. Then everything will be without any color on Let's go to get hub. Um go here on a change to the develop Mestre on See, The four commits here So first commit out of the victim environment we created the first Google glad function of deployed it on things their with me. So this shall have be just one commit Because every time you commit your changes you have to do it from the root directory. So if you do this hell world and then get ad and make get commit then Onley the things change it here in hello world will be committed. So don't do that again. Every time you want to commit your changes, go to the root directory and get at and do all off that process. So I hope you learned help to the blood your functions have how not to commit this error again and see you in the next lesson. 9. Using Sendgrid to write our second Cloud Function: I am. Welcome back in this lesson. I am going to teach you how to use an A P I in order for you to send emails using Google Cloud functions. So this will be the opportunity for you to learn how to use environment variables and also to add securities to our Google glove functions. Because, remember, we deployed a simple Google blood function last time, But anyone can access to your end point on. If they make a script for calling that endpoint and 10 million times, then will you will be screwed because, um, you just have only two million investigations. Vermont aan den. You will be charged for those additional locations. So first, let's go to descend Grid. This is a company called Trey Leo. It's a very good company, and they have the service Gold center. So you can see the description of the service here on you can try it for free. And if you click in this bottom, then you will be asked to provide your details too. Great an account. Um, well, provide additional details. Then you will have an account. I already have an account, so I'm going just to sign me. So that's signing. And they have my credentials already there. So I'm just going to logging. So this is the dashboard and, well, if you if you want to verify your account because it says here that number find account Charlie me Ted to 100 emails per day. Well, you can verify it and no problem. So we're going to explore these a little later. Let's go to our biter on Let's create another folder. So let's right legal on here. That's wait. Okay, new directory on. Let's say these folder is going to be cold. Ah, I don't know. Emails. Okay, so inside these emails folder, I'm going to great these Spieth, um, filed Gold Main. Remember all of our Bytom files most being mean main. Okay, No, let's, uh, its weight. Okay, let's go here to our dashboard and let's go to here where it says email a p I. So let's click here and thats click on integration guide. Okay, so let's choose these Web A B. I and here lead select item. You will You will see that this is very, very easy to integrate. So fear here we It says make sure you have the prerequisites. Uh, records by Thornton le Great and a p I key. Okay, so that's great. And my first a b i g. So this will be unique for you. Uh, I have to provide a name, so I don't know, cloud functions test will be the name off my A p i G. Okay, so they gave me these AP I Yours will be different, Obviously on day they say here to do this. We're not going to do this. We're just going to go ahead here on grade. A new file called that envy A But before doing that, I'm going to add it here. That e energy. Okay, so I'm going to add their file The envy. Andi, let's seem register and you file that association. It's just going to be next. Okay, so here, I'm going to say sen Grid A B I key is going to be equal to whatever they gave you here. So you just got beam and based, um, this ap, I keep inside the these this file on. Let's close it. Let's close this and here we're going to add another dependency. It's San Grid. So let's just add it 100. And here is the, um, the screen in order to send email. So it's very, very simple. That's why I like this a b i. But before writing this goat, let's speed install minus our requirements that txt. Okay, so in the meantime, let's define a function. This function is going to be called sent email, and it's going to except as a parameter, these requests. Then let's, um, copy this code here we have here. Let's just go be these board. Wehz. Well, these imports were going to take them out. Let's let's give them. Give them there. Okay. So, first, But we're going to do is to very fine request Jason. So we're going to pass a Jason object to these loud function. So remember, request get Jason silent, equal to true. Okay, then we're going to save parameters are going to be, um, sender. And they're going to be the receiver. Um, they're going to be what else? We need The subject of the male. We're going also need the message. So before doing this, we want to uh, no. If there is something in these requests, Jason. So remember, if request days, um, and Now we can do the following sander in request, Jason, etcetera, etcetera. But that's why I created these parameters to pull, nor therefore do the following. Oh, um, okay. For key in request, Jason for gay in parameters. So if all of these parameters are in a request, Jason, then we're going to say, hey, are sender is going to be request Jason sender? Um, a receiver was going to be a request days. Um, receiver. Our subject is going to be a request Days and subject on our message is going to be request Jason message. So let's initialize. Actually, these all of these variables first subject message. Also be empty strings and the strings and the strings and districts. Okay, so, elf, we're going to do something. We're going here to import, um, flask from flask. We're going to import abort. Okay, So I'm going to show you how we're going to use these aboard later. First, lest here, from email, send their here leads specified toe emails. Receiver here. The subject is going to be the subject bearable on here. The html content is just going to be the message. So you in the message you're going to specify a as HTML. Okay, so this exception we're going to delete this, But before the leading this, I want you to notice that here we have thes os that everyone that get sent great a pity. So remember in these the m file with specified descended applicators environment viable to be equal toe thes these applications they gave us. So we're going to get that from these m file and then we're going to send the message. Okay, so on. This is good. Andi, I wanted to talk you about something else before finishing this video. I know it's getting too long. Let's talk about H dtb goats. So if you Google that http codes and you have here in the first base rest ful that a p i you have all off these http goats. So if something goes wrong, So for example, I didn't give all off the parameters. I shall throw these 400 bad request. You can read more about this. And in these Elsa statement, I'm going to say aboard 400. So that's why. And this is this Is this abort its useful. We can throw this kind off errors. These studies codes. If none of these are at least one of these parameters waas not given, Um, And if something goes wrong, then we can also return the message, the status code for hundreds. And this is another way to do this. But here we're just going to give this status coat. And here we're going to return. The ever that gave us when trying to send a mail and also the status coped. So I know these videos getting a little love. So I'm going to stop here. See you in the next lesson. 10. Testing our Sendgrid Cloud Function: hi and welcome back. So we are now ready to death Star a new glad function. So before doing that, I have to modify some things here first. So before this angry day be I came. We're just going to write export on. Let's go back here on Let's write source That can be. And now we have said successfully descended a p I came to verify that we're going to print the government rebels. I have a lot So I'm going to search for the send rid one by using this grip on They found these same grid ap I came and it is equal to these very long string. Okay, So also, I want to tell you that I added these envy file in the get ignore because, um, this is an A P I key. It's not supposed to be exposed to the public. Remember, my rebel is public on. Well, I am exposing it right now because I need the tt this. But obviously, after finishing the course, I'm going to delete the A B i g. So no one can send mails on my behalf. But that's the reason why you shouldn't at these dnb files, or you shouldn't bush them to your brands again. So another change is that if this tribe block is successful, then we have to return something. Right now we're just printing this, so we're going to return his drink, OK? And that was goed off 200. And we don't need this rabble response anymore. So what does this 200 mean? Well, let's go to these http Responses that was goads and see that 200 is Okay, so it indicates that the rest ate the ice, successfully curry out whatever action the client requested. So in short, 200 means that everything went well. Okay, so I think now we're ready to test our new cloud function. So let's change Directory City to emails on. That's executing this. Command functions. Framework target, send mail. I lost my lost the buck. Okay, so now let's see what happens if I go here. It says bad request. If I want to invoke these cloud function from the browser, it is going to return me. But request. Why's that? Remember? You know, in our coat we are expecting just a Jason. We didn't specify here. Request arcs. So if we don't pass a Jason, these will be none. And so this condition will be false, so everything here will be false. And so we're going to execute the gold inside these else. A statement which is aboard with a status code off 400 on. If we go back toe our http responses status codes, then 400 means bad requests. So that's why we have bad requests here or 100 entitle. So that's because we can't enter or invoke this club function from the browser. But that's a game because we're going to invoke this club cloud function from boatman. So here we can remember pass Jason objects. They are like dictionaries. So the center will be my email from the university. The receiver will be me. The subject will be this for a new brand blood function on. The message will be high. If you are seeing this, that's because the glad function Waas involved. Okay, so now let's send this see what happens. Okay, So leads. See if I have something here. Yeah, so as you can see it, he's seen this spam folder. That's a game. Um, hi. You're Cindy's. That's because the cloud function was involved. And it is coming from my university. A male. So you can see everything went as we expected on these. Okay. Status? Well, this showcase drink was returned. And the status code shoe have bean 200. And here it is. 200. Okay, it took 997 minutes seconds on. Well, everything is working. Fine. So that's all for these video on See you in the next to one. 11. Adding basic securities to our Cloud Function: hi and welcome back. So as you're thinking right now, the blowing these clad function to Google blood platform will be extremely insecure and dangerous. Why? Because anyone who has postmen cool send a request specifying these parameters and the receiver subject message here they can boot any sender here. They can put any receiver in subject and any message so these can be very bad things. They can include insoles or pornography or something very bad. So that's why we need to add at least some basic security measures. Onda security measure we're going to take is very basic, but it's effective and it's gold Abe, you're talking on. Also, we're going to limit the methods allowed when sending these requests. So right now, we were sending this request with with this get method and will there are a lot of other methods like bossed, boot, badge, delete. We're only going to allow bust methods. Okay, so first we're going to do that. And we do We do that by saying if request method is different from most then aboard and we need to specify here, is that a scope? So let's go back to our http response Goats and all those goods that ah start with four are for bad things, actually. So, for example, 405 means method, not allow it. So this is what we should return 405. OK, so that's our first security measure. The other one is the Beerer talking. So if we go toe postman on D. C here in authorization Andi Cebu Erdogan. Then here we have to specify a talking, and these will come in something called the Heathers off the request. So first we need to create a talkin. So we need to create it on bass to other users and say, Hey, this is the beer took and you can use if you didn't have this beer took and then you can use my service. Okay, so we can create. Ah, they were talking like this in the beytin council. Import secrets. I'll say secrets. That token had 16 and give us Iran them strings. Okay, so these will work. There are obviously ah, against our way longer than these. And we're going to see export. We're going to say export access. Duggan is going to be equal to these string here. So, in order to put this into an environment of arable, we're going to say source that envy. So let's see if it was said greatly rep access again. So we have to, um, environment, rubble duty, accessibility, which I don't know what this is for, but we have also our access still going here. So we have now said our access token. And we have to say we have to, um, get first the token received from the Heathers. So we're going to say be read, tucking. I was going to do request that heathers that get authorization. And here I am going to split these on. Take the second s drink from this, a split. So here, this part of the code is going to return me as drink a string that is going to consist of beer, his base and the actual token. So as it is a string with a white space, I have to split it, Andi. Then take the second thing from the split, which is going to be the token. Obviously, you will have in production to enhance these how you get the we're talking because, for example, and it can get very er the authorization can only get the token and the beer token. The token made made maybe empty on some things like that. So you have to specify more cases, but we're going trust him that inner headers The beer token is going to be bearer on. The second thing is going to be the token. So now we're going to say sacred. Keep us that end, Really? That get access token. And we're going to say, if you're talking is different from the secret G, Then we have to abort. We have to a board with a certain, uh, status coat and that the status schooled will be this one. Unauthorized. So these are our response indicates that the gland try to operate on a productive resource without providing the proper authorization. So I think that goes well for us. So let's go to our emails directory. Um, here. Say functions. Framework minus minus target. Um, send mail minus minus. The book Onda leads, for example. First, um, Sandy's with the body and the sender will be my university email account. There are receiver will be me. The subject will be these east. Yet another cloud function test on the message will be Hi. These Waas sent successfully. I don't know anything you want to send here. Okay, So I'm going to send this first with the get method and see what happens. And without any authorization So that seem. What is the response of these? So as you can see the response Waas 405 Method not allowed. Why? Because we are only authorizing bossed methods. So that was okay. Now let's go with the bust. Let's add these same body and the authorization with a beer. A token So I'm going to copy these. I'm going to baste it here. But I am going to change the first number from 3 to 2 on DSI. What happens? So as you can see their response Waas 401 Another Christ. Why? Because these Bura token is not a valid your token. So I have. If I put back the three then it gave me a status code. Okay on let's see my mail leads. Go to my mail and see if the male Waas sent or not. So it was sent successfully. As you can see, these Waas sent successfully. Okay, so in the next video, I'm going to enhance these, uh, he's a script. So in order, for example, What if I am not sending and beer token, but an A P I g or no off? So we have to We have to enhance all of those teeth. The details. I'm going to do that in the next video. See, then. 12. Improving the way we get the Bearer token: hi and welcome back. So in this lesson, I'm going just to enhance the way we get this bureau talking. So it is more consistent. So I'm going to define another function. Gold. Get your talking, get your cooking. It's going to have the request. And here I'm going to say you're a tuck in. You were talking, going to be equal to request that Heather's get authorization and if there is no authorization, then I'm going to return them. So if not beer talking, So if this is none that not none is going to be true. And so we're going to board we a 4 401 So we didn't have these aboard Important. So I'm going to import aboard from these top level so we can use it from both, uh, your token and from sand in jail. Okay, So if there is no beer token, then we're going to a board with a status code 401. If there is a beer token, they were going toe split. This and we have three cases here. So remember the first part of the beer token must have the string Beerer on the second part must have the Dogan. So, uh, ive part zero, That is the first. It's true. And we're going to lower case. If this is is if this is not equal to mirror, then we're going to a board. 401 l else If, um, the Len off the Bard's is equal to one then aboard 401. So I'm going to add a garment here. So these means that the broken waas not found here, I'm going also to add a comment. I'm going to say the authorization authorization Heather must start with, um here. And the other one is if the this least as more than two elements, then I'm going toe aboard. Also, I'm going to say, um, the authorization. Heather must be off the form Beerer talking. Okay, so that's everything. That's all the cases we can have on if nothing happens here. If none of these conditions is true, then I'm going to say that they were talkin is going to be equal to Bard's one, and I'm going to return the beer. So instead of doing this, I'm going to say, get beer token. Good. We're talking. I'm going to pass the request so That's how you enhance these, the way you get the token. And while you can test all of these cases if you want in Boston. So that's everything for this video. See you in the next lesson. 13. Deploying our Sendgrid Cloud Function with environment variables: hi and welcome back. So now I am going to Did you how toe the blowing these Google blood function we created? So the first thing we have to do east to create two new files inside these emails folder. So let's actually write league on the e mails folder and at these new file requirements that the X team on in the get ignore leads these thing here. So e mails that envy the Jamel So we're going to great. Now these new file that you envy the demo that's reload. So now it's in that color, and this means that these file will be ignored. So I'm going to explain you why we need these two files first. These that envy the JAMA is going to have the same information as these that Eun bi file. So we're going to have these send great A P I key. But instead of this equal sign, we're going to put a call in here also, we're going to have these access silken here, but instead off the equal sign, we're going to have the column. Okay, so now we have this information in this that envy the demo. That's why I put this in the get ignore because I don't want to expose credentials in a public ripple. Also, in these requirements, I'm going to add the scent, greed, baggage. I'm not going to add the functions framework because we don't need that. In the deployment off these function, we just need, um, flask and send grid. So, yeah, I'm going to need flask also on. That's everything I'm going to put in these requirements that txt Um what else? I don't think I need anymore. So I need these two files because Google needs to know that I have here on a file a demo that contains environment, Bibles and their requirements. That 60 that is going to contain the dependencies only for these cloud function. This requirements that txt contains the dependencies off all off my projects. So for emails and for hello world on why I adhere flask on here. I am not adding flask. Well, functions framework did in stuff last for me. But I am not installing functions framework here, so I need to stuff last here. Okay, so that's everything. Now let's actually deploy this cloud function eso In order to do that, we do the following de cloud functions. Deploy. Send mail. Um minus minus and bars filed The intervene The gamble minus minus runtime by from 37 minus minus. Trigger age DDP on. In the meantime, I'm going to add these, uh, in the documentation. So I'm going to say, here the blowing and glad functions. We've environment variables. Andi. Oh, there dependence. And And Okay, so I have cured this method message. This says alot unauthenticated invocations off new functions. I'm going to say yes. I'm going to explain you why this message always shows up because we already added some securities. So why it is telling me if I want to, uh, invoke if I want to allow unauthenticated invocations. So I'm going to explain you this, But before let me finished the documentation. So we have grade that envy the demo file and a requirements that 60 um 60 file in the same directory of our main that b y, and then run the following government. And here I'm going to right the command, which is a big, loud, um, functions that blowing the function. Name, French name, minus, minus. Ever. Vars file. But envy the demo. No, minus minus, um, runtime by from 37 Um, trigger minus minus trigger age to be. So anyone who reads these documentation is going to say, Oh, I need to run this command. I need to great these files in order to deploy my a Google blood function. So now it is deployed. Andi, I'm going to copy these You Earl. Sorry. And I'm going to basted here. Okay, so in the body, I'm going to send this subject, this message, the sender and these receiver, and I'm going to send the request and see what happens now. Okay, so it is sending on it gave me. Okay, so now let's see. Um, I have something here. Okay? So sometimes this happens. Because I already sent a message here. Andi, as I didn't verify my account in sen grid. Then it is coming in the spam. So let's have here death from D C. B and some another. Another message here. That's sending again. Okay, so now it is showing me here. So the problem was that if I sent the exact same message, then outlook is not even going to show me the message. Not even in span. So was You can see now I can use these Google cloud function from post meant and it is the same process. But we needed to deploy to the cloud. So I was going to tell you why they showed me these message alot unauthenticated implications off new function. Well, that's because I can't even put more security to my Google. Glad functions if I go here and I refresh. Okay, so there should appear my send email function, So yeah, it's there, Onda, If I go here, I will have these. I am. And here I can have roles I can see. I can add a person here, for example. I don't know someone email that come and they can assign him a role. And these will this person will be able tow manipulate all of my dashboard All of my google glad functions. I love my container registry Everything depending on the role I give him on. Also, if I will have said no here. Well, just the people that is allowed from these I am will be able to call these, um Google cloud function. But we went everyone with the bearer access token and with these very eyes access token. We went everyone that has these to invoke our function. So that's why I boot. Yes. And they give me all of this information. The version i d the statues. Um, well, all of these useful information and I can use it here in my Boston on everything went as expected. So it's very, very useful These things. I hope you like this video on. See you on the next lesson. 14. Understanding why CORS is blocking our Cloud Functions: Hi and welcome back. So we have successfully deployed are glad function we have tested We have used with postman . But now suppose we want to use these club function from a web app, for example. You seem JavaScript, for example. Then we will need to call it, um just as we call it from postman. But obviously using other type of goat. So here I have the goat disease. Pure JavaScript on gas script. We have these fetch method. So in the first parameter off these fetch method is these well, our our endpoint, which is thes one on the second parameter east. A Jason object which were with specified the method which disposed the Heathers, which is the authorization with with our we're talkin our content type. That will be Jason on the body, which is what we had in force Mint. So let's just got b and based this And in order to execute Gava script, the easiest way is to open the council in your browser. We will control shift Ieave urine Lennox. Um, let's copy and paste it on, then enter. So, as you can see, we got an error here, and it says here access to fetch our endpoint from origin. Laguna has been blocked by course policy. So what exactly is this course policy? So Gore's let's actually search It is gross origin resource sharing. So when we try to call an A P I or iCloud function from the rouser, it's different as if we were calling it from Postman. Why? Because by default, the browsers don't allow. Don't allow you to call a B I's unless the endpoint allows you to access that a. B I so you can read more about this and well, in summary, ive our blood function doesn't allow the browser to um to enter. Then the browser won't have any authorization on this is going to happen that the defense is going to be blocked by course policy. So that's everything you need to know. And we have to fix obviously this problem, and that's what we're going to do in the next video 15. Committing our changes before we continue: hi and welcome back. So before we continue with course, I want to commit all of my changes. So remember, we have to go to the root directory, and then I do the following at that commit. And here I'm going to say implemented, um sand, male, loud function and deploy did to Google Cloud platform. Then we get Bush, and that's everything I wanted to do. So see you on the next lesson. 16. Adding pycache to .gitignore: and welcome back. So in the last lesson we committed are changes but noticed something that went wrong. So if we go to the emails folder, you're going to see this by cash folder on If we go to the hello World folder, you're also going to see these by cash folder. This is not something we want to have in our rebel. So we go to the terminal here and we're going to add it to the getting or by cash and slash for specifying that this is a folder. But the get ignore on Lee ignores files that are not already at its Oh, my gosh is already added. So it is not going to be ignored. So in order to ignore it after we write it here in the get ignore, we have to do the following get our M minus R minus minus cashed. Don't on. There you go. Nets commit again Are changes on, say related the I cache folders on Get Bush. So this is the way how you ignore files that are already added to your rebel. So that's everything I wanted to tell you. And let's go to the next lesson 17. Adding CORS to our Cloud Functions: hi and welcome back. So now we're going to add a course toe one of our cloud functions. So here in the Google Cloud platform, let's go to cloud functions that search for the cloud functions. So here we have I have three glad functions deployed Sendmail Hello world and these scores enable function that I was testing out. So let's goto our hello world on then let's go to that trigger top here we will have the endpoint, the euro. So let's copy the link address on Let's go, Tony in top. So here in the new top, you can write, leak and go to inspect or control shift I, if you want, it's go to the council. And let's clear this council with control l OK, so I'm going to teach you how to fetch on, then point with JavaScript JavaScript because we're going to write JavaScript code here. So we're going to say, fetch, we're going to put the euro and here we're going to send some barometers. So I'm going to say I want to bust. I want to make this request with a bust method. I want to add some Heather's Andi Heathers are going to be okay. Contin type. So content type is going to specify the what are we going to? The format of the debt that we're going to send in this case and will be Jason. So we have to write this obligation, Jason. And also the body. It's a Jason. We have to say Jason got a string defy a strange if I And inside this Prentice's, we're going to ride the object. The dais, um, or the dictionary. Whatever you want to call it, I'm going to say name. That is on a last name Adam in days. Okay, so, uh, luminaries Okay, so that's the fetch method. So these is a promise. So we have to then receive a response on from this response. We're going to apply this method called text. So these extra method is going to return us the hello world or hello, the Biederman. That is whatever On then, where we have toe council. Look that response the text. So result is going to be gone. Sold. Look. So that's how you bring something in javascript. This council locked is equivalent toe brain team Bytom. So don't worry. If you didn't fully understand this because thesis pure JavaScript. But this is how you make a request to our cloud function. So let's see what happens. Well, you can see access to fetch this. That function has been blocked by course policy because no access control allow origin. Heather is present. So how do we fix this? Well, so what is happening? First, the browser is first sending to the blood function, which is? The server is sending this request with a method gold options. So then the server has to return some Heather's and these headers there has to be these access control alot origin. So let's see, what do we have to do in order to fix this problem? So as I told you, the server first since the request with these methods gold options. So we have to return some heathers. If, um, if we receive these method options. So the heathers Hey, there's will be the following. The 1st 1 is going to be access control. Allow origin. Okay, so here we can specify a specific domain. So, for example, if you're making these requests from facebook dot com, then we should do this. But if you are, if you want to allow everyone to access your cloud function. Then just at this asterisk, then we can specify access, control, allow methods. And here I'm going to say I'm going on. Lee. I'm going to allow only the cost method if you want to allow any method than just at this. But I'm going to say I just want bossed methods. Then, um, we can also specify the Heathers allow Heathers others. And remember that we said this gun tintype, we're going to say to the browser, I just I'm just going to allow this content. Heather Andi. Lastly, we can specify also, um, these control max age. So this is going to tell the browser that if you make another request, then you can, um, like, remember these Heathers by within one hour. So you you're going to remember these Heather's one hour or 3600 seconds, and then we're going to return. Um, well, nothing. These a status code 204 on, um, these headers. Okay, so we're going to actually see what is happening here in the terminal. But before doing that, let's finish this goat. So this thing here is gold. A breath like request. So before doing the main request, which is these goat here? The browser is going to do this breath light request. Then there comes the main request on there. We have toe also, um, send some Heather's and this is going to be just these thing here. So let's at this. And then here I have to, um, return the stethoscope. So remember if everything was a cane, I returned 200 and some Heather's, which will be is one 204. Let's see. What What does that mean? It means no gun tint. And that's okay, because here we're not returning anything. We're returning an empty string on here. We're returning. What? It is supposed to return. Hello? Name last name. And also these Heather right here. Okay, So this is everything we have to do in order to allow requests from the rouser. So now let's deployed with deep loud functions. Deploy. Hello, World minus minus. Right. Runtime by from 37 minus minus. Trigger. Http, so remember that Wasim to rid me. I just copy and paste it on changing their functioning. Okay, so let's deployed on. Wait patiently for it to deploy aan den we're going to make exactly the same request. But now the browser shall not show any error. So we're going here to than UTEP. Here we have the goat. Let's wait for these to the blowing. I'm going to have these already here. So now it is the blood. Okay, so now I'm going to do exactly the same request. You can verify it's the same thing. I know I don't have any error. Why? Because now we are managing that course. So that's everything I wanted to show you here in these lesson, we fixed this problem successfully on Well, let's actually get at this goat. So commuter changes. Let's change directory. Remember to our root directory. That's get at, Let's say, get commit that Say, um hello. Course requests in the hello World Glove function on. Then let's get Bush. Um, there it is. We have everything up to date. So I hope you like this video. See you in the next one 18. Creating a Firestore database and adding Google credentials to our project: high and low come back. So we're going to see the last thing, this course, which is how to schedule blood functions. So we're going to take advantage off fire base and all of its services. Specifically, they know SQL database, which is far store. So go here to the database section on That's great. A database. So that a basis ha half, um, certain rules. So, for example, here, if I start in production mode, then all their body rates and rights will be the night. If I start in test mode than anyone with my reference will be able to read a writer that I race for 30 days and then they specify me here something that's gold fire stool rules. So we're going to start this in production mode because, I mean, there's no need for anyone to read or write my database. So let's just start this in production mode. So it says after you said this location, you cannot change it later. Okay, so done. Now, I will have access to a whole new World gold fire store. And also I will need, um, some permissions in order to access or read or write or modified documents in these databases. After this is all set up, that's what we're going to do next. Get the credentials. Okay, so these is my, um, no SQL database. We're going to explore it later. First, let's go here to settings, project settings and here in service accounts leads. Well, you can just buy from here. But the thing here is you have to click on this bottom where it says generate new private G . Then it says, here your private G gives access to your projects. Firebase services keep it confidential and never started in a public repository. So they are very, very specific about this. So it's January Dickie. And then let's download it to where we have our our repositories. So here I'm going to Let's change the name off these. As you can see, it's a day some file, but let's change it to Credit firebase or Google credentials to be more specific. Google credentials aan den. Well, obviously remember, we have to put this in the get ignore because we don't want anyone to access these credentials on. I'm going to tell your story. I once exposed this credential. This credentials and something very very happy. Very, very bad happened. So let's add these Google credentials. The Jason let's reload everything. And now it is ignored. So let's get at everything. Let's get commit. Andi, put a message here at it. Google credentials two. They're getting more. Um, Okay. So yeah, and lets them get Bush these things here. Okay, so that's everything I'm going to do in these video. In the next lesson, I'm going to teach you how to use the fire base as decay. See you in the next lesson. 19. Writing and testing a Cloud Function with the Firebase SDK for Python: Hi and welcome back. So, in this lesson, I'm going to teach you how to use the far base as the gain biting on. We're going to create a new new Google. Glad function on then we're going to schedule it. So first, go to them. No SQL database. It's cool. Fire store. And here we're going to start a new collection. These collection is going to be gold expenses on Dhere. We're going to save documents with these fields. So the date off the expense. So suppose I am. I am saving my expenses. This will be a time stamp. I'm going to select today's date on well this time. And also be expense The amount of the expense. Um, it will be a number. Suppose I The number is 100. So we're going to create a cloud function that every time that it is invoke, it's going to create a document with a random ivy on with these two fields the date or the time where it is invoked and the amount off the expense. So maybe these will be better if we go leads, um, created at created at times them. So I think it's a bear name. Okay, so every time we invoke this function, it's going to grade these two fields and your document with these new fields. So let's go to our by charm. And here I'm going to have a new directory and it's going to be gold and no expenses. And here I am going to boot main file and also a requirements file requirements. Subtext. So we will need here, the fire base at me on. We're also going to need it here, so I'm going to do BB install. So let's go back here. City. We've been stone minus our requirements that 16 and okay, so I installed it before. So it's going to tell me Requirement already satisfied, but for you it's going to be installed without any problems. So let's close this file and here I am going to actually write my, um, my Google Club function, so that's import for a base. I mean, and here leads also import from firebase at mean It's import fire store, and we're going to create these variables. Our base, I mean, that initialized up. Well, actually, we don't need to said these dry verbal, um, we're going toe also make reference to our database to our db by saying first or that client. So here I'm going to grade now. My function, my blood function. It's going to be gold, said Expense. It's going to except it's a barometer request here. I'm going to import from daytime import daytime. We're going toe also import random. I'm going to try to do the following. I'm going to make a new document, Ivy. So let's say db dot collection expenses that document. So by doing this where reference we're referencing first our expenses collections on, then we are creating a new document I d. Randomly. Then we're going to actually set data here. I'm going to ride a dictionary with the date the time that now. So it's going to take no on the expense key with its value, which will be a random into jer from 1 to 200. I don't know. And if everything went okay, we're going to return again and status code 200 in the except Block. We're going to catch the exception as he and we're going to return these ik with the status code for 100 because something didn't go well. Okay, so Now this is everything for our flout function. Let's actually test it. But before testing it here I am initializing the up and in order the stakes credentials. But we have to specify these credentials in on environmental variable. So this environment barbell has to be called Google application credentials. And we're going to reference to the absolute bad bath of these, um, of these Jason. So we're going to go be on basted here. Then we're going to do source that unity on. Let's see that environment variable. Bring em a grab. Well, and as you can see the environment variable West said as successfully. So that's change Directory to wear expenses directory. And here leads this our new function with the functions framework minus minus. Target said expands minus minus the buck. If something went wrong, we can debug it. Okay, so now we can go here. I'm not going to click here because it's very slow. If I do that, I'm just going to type these. You're all here. Okay, so it returned. Um, okay. And as you can see, a new document was created. Let's reloaded. A new document was created here. Let's do it again. Well, it looks like the document is created two times, so maybe this is a problem. We're doing something wrong here. Yes. So it's actually doing to ah, two requests these world on this one. It's here, actually, taking the fabric on that Michael on to be 1 100% honest. I don't know why it is doing to requests here, but Okay, so it's doing to request. We can do. I don't know. What what? Why is it happening? Let's just stay with the fact that two documents are created every time I reload this page . Okay, So now that's everything I wanted to show you. Maybe these won't happen when we actually, uh, deploy dysfunction to the cloud. And that's what we're going to do in the next lessons. Okay, so see you then. 20. Deploying our Cloud Function to GCP: I am looking back. So let's actually now the blowing our new cloud function. So let's go toe to the read me. Let's copy this command. Let's based it here. Ok, so here is going to have an error because this function name doesn't exist. So here we have to replace with our functioning, which is set expense. Okay, so we modified this on then? Ah, we deploy our new cloud function. Andi will notice that this cloud function is very, very insecure. Because if someone gets our endpoint, then they can invoke our cloud function as many times as he or she wants. And I were ah, that I base is going to be field with documents. Maybe we don't want that because the size of these is going to be very, very large if we don't control that. Okay, so let's wait for these to give us the end point, and then we're going to invoke that Glad function and see if that error remember last time it was invoked to times was fetching two times making the request to times. I don't know why. So let's wait patiently for these to deploy, and that's actually the lead the collection. I'm going to delete it in the meantime, and I'm going to create it again. Expenses? Um, auto, I d save. And I'm going to delete these Doug human here so we can see the noon. The new documents creating. Okay, so it's taking a long time. So we invoke the blood function on here. We are going to see them. Okay, so now it's deployed. So let's Cubby. Well, I think I blinked. Yeah, I clicked that on into eternity. And as you can see, um, yeah, itwas created the new document. Leads, um, working again. Another like him. So now it is. No, it is not invoking two times like last time. It is invoking only one time. Okay, so it is working at as expected. It's creating a date now. Now date the expense. It's around the me into gear. So it's working us. Expect so in the next lesson, we are going to schedule these cloud function. See you in the next lesson. 21. Committing our changes: hi and welcome back. So before doing anything, let's commit our changes. So let's go and change directory need of you. Go meet Menace. Um added a new blood function that said data to a collection in fire store Said's expense data expense data. OK on, Then give Bush. Okay, so that's everything. And let's continue in the next lesson. 22. Scheduling our Cloud Functions with Google Scheduler: hi and welcome back. So in this lesson, I'm going to teach you how to scale our blood functions. So first we have to do the following the cloud components install bed. Okay, so I have already installed it. So this message is going to be shown to me or components are up to date, and then you do become declawed components update. So all of this is going to be added to the documentation, so don't worry. And then we're going to publish a topic or great a topic with this Bob sub message pattern . So I'm going to explain you what it's pops up its first create this topics great, and it's going to be allowed function best. And then I am going to actually subscribe to these, uh, the big bub sub sub scream shoes. Great. Uh, ground sub The big ah, glad function test. Yeah, I'm going to add all of these to the documentation, because, uh, I don't expect anyone to memorized this thing here, so let's great here the boy. Ah, or schedule cloud functions. We execute the following commence. Then we at all of those commands. The 1st 1 was declawed. Components install better The other one waas the cloud components of date and the other one where all of these g here, I'm going to change these two Dabic name. And here also I'm going to replace we big name the big name. Okay, so sheriff it Now we have everything. Ah, in the documentation And then we are going to go toe the Google blood platform And here we're going to these A schedule. Glad to schedule the schedule. Er I'm going to also go to their functions to the cloud functions to see the end point because I forgot thean Point. So let's go to functions again. It's a little bit slow, so that's weight functions. Glad functions. So here in the cloud schedule, er, I'm going to greet a job on also I'm going to OK, so here's my set expense blood function. Remember, you can see what the Here's the in point in the tub trigger in the trigger. W can be the end point because we're going to need it. So name. And I knows that expense. It is going to be the name. The's club function creates documents with random data on the frequency. I'm going to put a bullet later. The time zone is going to be, well, my country's Ecuador and we have two time zones Galapagos Time and a quitter time. I'm going to select 1/4 time because I don't leave in Galapagos on target is going to be these age GDP. I'm going to baste the blood function and here in the a method, you can put whatever I'm going to put get because we're like posting every any anything. And here in the Frick frequency, we have to specify the Grum job for four months off these of the frequency. So if you don't know what Grand tab is, then just Google here and you can read a lot about this topic that, in essence, we have, like five feels the 1st 1 is mean it hours. They have mined the month on the day of the week. So there's a very useful Web facial from top group, and you can say grand top every Monday, for example, and then in this grant of that guru, then it is going to show you the format that you have to use if you want everything to be at 00 on Monday. So you can also a ride every you know, every 10 minutes on the ground. Abduct Guru is going to give you thes format for you to use it. So I want grant up every minute. So let's see what what it is. It is all ass risks. So yes, I'm just going to got be on based. Ah, here in the schedule. Okay, so this is going to be executed every minute, So let's just grade the job on here. We can see the locks. So we have to actually wait a minute for these, um to execute, But we can run now and then you're going to see that. So let's delete all of these documents. I don't delete all the collection, so let's do this. Let's still it this on leads lead these documents. So let's execute. That's wrong. Now then, you're going to see that these waas created So if you want, then just wait a minute on another document. Shul be created here. So if you want, just wait on See that I am not line document is going to be created. So that's how you, um, great jobs. You can have more things here. So, for example, um, and the http method can be passed here in the body. You can put anything you want, or if you want to use any other method, then you can use it. But basically, that's how you a schedule allowed functions. So, yeah, we waited a minute here and now the document was created automatically, so I did that on purpose. Ha. OK, so that's everything I wanted to tell you. That's how you spell GLAAD functions with these Glad scaler. It's a very, very useful tool that Google Cloud Platform offers. So see you on the next video. 23. Deleting Cloud Functions: I am. Welcome back. So one last thing I want to show you is to how, actually, to the elite, our deployed cloud function. So we have to say bye bye, toe our blood functions, especially me, because I have exposed all of the endpoints and you can do whatever you want with him. So leads do this club functions the lids on, for example, discourse enable function course enabled function. So bye bye to these Google function. Let's put this in the documentation. So the leading a cloud function loud function. Okay, so I going to say yes. Here, Um, here. I'm going to say to the lead a cloud function run the following command here. G cloud functions village, uh, functioning. So let's very fine that the cloud function got deleted. It's refresh this on and there you go. No more course enabled function here, so let's at these documentation. So it's coming our changes by saying at a documentation too. Well, we didn't commit those changes. So to a schedule, God functions how to delete them. Give Bush. Okay, so that's everything for this video. See you in the next one. 24. Conclusion: Congratulations. You made it to that last video off these course, so that's a great achievement. And what you learned in the scores was to implement good blood functions with python. We used the virtual environment. We created meaningful documentation. We use a version control system that is get up. We tested cloud functions before deploying them like crazy people. We deployed them when it was necessary, and we tested them with Post meant. And we also tested them from the browser. We added some basic securities. That is a bitter talking. Also, there are more complex ways to add securities. But we reviewed very simple way to a basic security. We added course so we can fetch our glad function from the browser. And we learned how to schedule glad functions. So that's a lot off things you learned on. Well, if you like this course, follow me on YouTube or what? Well, subscriber, Negative. And you can connect with me on LinkedIn. So see you on the next course. Bye bye.