Installation and the CLI

The Serverless Framework comes with its own CLI so that you can manage and deploy your services. This is also where new functionality can be exposed by installing community plugins. Let's get started:

  1. To install the framework, we need to make sure we have Node.js and node package manager (NPM) installed locally.
  2. Then, we can go ahead and run a global installation of serverless. The global option will make the serverless package available to the whole system, instead of just installing it on the current working directory. The installation also sets up a command alias so that you can use the shortened sls instead of typing out serverless to execute the CLI.

Run the following command to install the Serverless Framework from the NPM registry:

npm install serverless -g
  1. After you have installed the framework, you can run the --help command to get a view of all the options that are available:
sls --help

Running the preceding command will give you the following output. Your output could be different from what's shown in the following screenshot, depending on the version and plugins you've installed:

Commands and plugins available in the Serverless Framework CLI

We'll explore some of these commands in the next section, where we'll create and deploy our own service, but clearly there is a lot of functionality here that is straight out of the box.

The last thing we need to do to be able to interact with and deploy to our AWS account is to set up some credentials for the CLI to use.

  1. We need to create an IAM user with an appropriate policy and enable programmatic access. This will give us a new user that doesn't have any permissions to access the console but will create the access key and secret access key that we need to be able to use the AWS CLI. There is a blog from the Serverless Framework that explains all of the permissions that are needed for the framework user in detail. You can find this in the Further reading section, at the end of this chapter.

The serverless CLI will look at the environment variables for your access keys first, but you can also use the AWS CLI's own configuration command or the serverless config credentials command to create a new profile. The details will be stored in a file in your home directory under .aws/credentials.

  1. In your IAM policy document, grant the user the appropriate permissions for your use case. If you're just starting out and using a fresh lab-type AWS account, then you may want to assign the AdministratorAccess policy to minimize the amount of troubleshooting you might run into. If you're developing services that will be deployed to multiple environments, including production, then you should consider creating your own inline IAM policy that follows least-privilege principles.
Introducing IAM permissions boundaries is also a great idea to minimize the risk of privilege escalation.

Now that we have covered the prerequisites, let's move on! In the next section, we will create and deploy our own service.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.133.61