Deploy Serverless Functions to Production on Netlify using the Netlify CLI

Jason Lengstorf
InstructorJason Lengstorf
Share this video with your friends

Social Share Links

Send Tweet

Netlify makes deploying to production a breeze by configuring your Netlify CLI to your Netlify account and integrating with GitHub.

We'll log in to Netlify through the CLI and initialize a site by completing all the options that the CLI runs us through. Once this is done, Netlify will trigger new builds for your site every time you push to GitHub.

Instructor: [0:00] To deploy this site, we need to make sure that it's up at a GitHub, GitLab, or Bitbucket repo that we control. That way, we can point Netlify to it. I have this up at learn with json/serverless-functions.

[0:12] You can get a copy of this by pressing the Fork button in the top right, or you can delete the .git folder in your current clone and re-initialize and push that up to your account. Either way, as long as you've got that git repo, you're going to be able to do the rest of the steps here.

[0:30] Next, we're going to run netlify login, now that we've got the Netlify CLI, and that is going to take us over to our Netlify account. On this screen, it's asking us for permission to let the Netlify CLI access our account. I'm going to authorize that. It says, "Great, you've authorized the CLI." You can close this, so I'm going to close that.

[0:55] Head back here and it says, now, I'm logged in. If I run netlify status, I can see that I am logged in as me. That's what I want.

[1:05] Next, we're going to initialize a new Netlify site by running netlify init. This is going to tell Netlify to create a new site. We're going to select that option. Then we're going to choose which team we want to put it on. If you've only got one team, you'll only have one option. I have a lot of teams, I have a lot of options.

[1:24] I'm going to choose my team here. I don't really care what this one's called, so I'm just going to hit Enter for a randomly generated name that's going to give me the name of suspicious banach with a hash. This site doesn't have a build command. I'm just going to hit Enter. For public, I don't want it to include that full path. I'm just going to retype public as my publish directory.

[1:47] From there, it's going to build us a site. I can run netlify open in my command line, and it's going to open up the site in my browser. We can see here. Here's the site running. It is deploying. If we look at the build log, we'll see it's off and running. The build's already complete. We found our function. This thing is live.