Build Serverless Endpoint using Serverless Framework

What happens on deployment

Transcript

The Serverless Framework gives us the means to monitor our services after we've deployed them. But to do this, we do need to set up a serverless account on the serverless dashboard; from our command line within the service we've been creating, we can just use SLS login. This should now open up our browser.

Once within our browser we get the option to sign up, I'm just going to click the sign-up link at the top there, and then I can choose how to sign up, I can either enter in email and password manually or I can sign up through GitHub or Google. In my case, I'm going to sign up with Google.

Once you have registered, you should get to a screen that starts walking you through our process to sign up. So on here, we just going to click next. It's asking us to choose a username for us to use. I'm just gonna stick to the default that it's given me because that'll be unique. Once it's created the user, it's asking us to create a default application name and we can name this whatever we like. I'm just going to leave this to the default called my-app, but you can name this whatever you like.

Once you've continued, you should get to the screen about deploying a sample service. You can feel free to go through this if you like, but we are going to be doing this ourselves so I'm just going to close this right now and just continue to the next screen. This is where we should see applications and my-app.

At this point we want to go take a look at some profiles and profiles are a feature that help us control how our services that we're going to be built get deployed into our AWS account. So let's click on profiles at the top and we are going to be just using the default profile. In future we'll be going into more detail about what profiles are and how they affect our ability to deploy and manage our AWS services. But for now, let's just open up the default profile.

Once it opens, you'll see it asks us about AWS credential access role and you should have a link here to create a role wizard. When you click this, this will open up the AWS account in your browser. So let's just go ahead and click that link.

When you click that link, you should see the creator roll screen here with the account ID for the serverless framework. And we're just going to click next to permissions. By default it will ask us to set up an administrator access for this user or we are going to leave it at administrator access, but later we will be able to look at setting up a custom profiles and so on.

So I'm just going to go next to tags. Tags is where you would go ahead and configure a certain values that you want to propagate through, any resources you create in AWS for like the department that you might be in or so on. In our case, we're just going to leave this blank and continue to the review page. On the review page, let's see everything that we're going to be setting up the role name needs to be unique, which it will be in my case. And once I'm happy with this, I'm just going to click create role.

Once I've created the role, I should see a message about the role being created. I'm going to open up the role I just created because we need to copy something from it. And I'm gonna click the little clipboard icon here to copy this ARN for my role. Once I've copied it, I'm going to return to my profile and I'm going to paste that ARN into this, input box And then save and exit.

Now we've returned to our editor and I need to go to the top of the serverless.yml file. I'm just gonna scroll all the way back up and up here we want to add in two new properties to link the service we've just created with our new, the organization and application we've set up in our dashboard account. So to do that, I'm going to add app and if you remember, I named my app, my-app, and then I'm going to add an org property here as well.

If I go back to my dashboard, I should be able to see what my org property is and that would be the username that I've set up. I could create an additional organizations if I wanted to separate this out better, but I'm just going to use what was already created for me and that is garethmccumskey2 in my case. Once I've got that in, I'm going to save my file.

When I used a serverless log in previously, it opened up my default browser for me to register my new account and then it should have come back with a, you successfully logged in message. If not just use SLS login again. Now that we finished registering, log in and make sure you select the correct account that you created with previously. And now we should be logged into our serverless account on our command line as well.

At this point, it means that we can also run a deployment. So let us go ahead and deploy our service that we've just created.

The first time we deploy a service in this way, it may take a couple of minutes because it will be the first time that the service is being created on our AWS account, so this may take a little bit of extra time. Once deployment completes, we should see a message about publishing our service to the serverless dashboard as well as successfully publishing it, which should also see is a URL to an endpoint that we can use to run our Lambda function so let's go ahead and control-click that to open up in our browser. If you run that in your browser, you should see the message that we put in our Lambda function hello from serverless.

What's cool about this is that in no way did we have to do any of this manually within our AWS console. We could just set this up in our Serverless Framework, use the deploy command to deploy this into our AWS account, and now we have a working API endpoint that is returning the data from our Lambda function that we wanted. There are alternative ways for us to have done this deployment, on the serverless.com website, in our documentation, there is a demonstration of many different ways that we could authenticate into our AWS account if we didn't want to do so through our dashboard.

Go through to docs, AWS, credentials and this page shows with how to sign up for an AWS account, creating a specific user in AWS for us to use, and then setting these access keys on our local machine instead of using a role through our dashboard account. So if you prefer to use this method, feel free to read through the documentation here on how to set that up.

Get updated when a new course is released