Serverless 简明教程

Serverless - Installing

另一个 tutorialspoint 教程已经介绍了 Serverless 安装。在此重新说明一遍,并作一些修改和补充。

Serverless installation has already been covered in another tutorialspoint tutorial. Reproducing it here, with some modifications and additions.

Step 1 − Install nodejs

首先,您需要先安装 nodejs。您可以通过打开命令提示符并键入 node -v 来检查您的机器上是否安装了 nodejs。如果已安装,您将获得节点版本号。否则,您可以从 here 下载并安装节点。

To begin with, you need to first install nodejs. You can check whether nodejs is installed in your machine or not by opening the Command Prompt and typing node -v. If it is installed, you will get the version number of node. Otherwise, you can download and install node from here.

Install node

Step 2 − Install serverless using the npm command

您可以使用以下命令安装 serverless(npm 代表 node 包管理器) -

You can install serverless using the following command (npm stands for node package manager) −

npm install -g serverless

您可以通过运行 serverless create --help 来检查是否成功安装。如果成功安装了 serverless,您会看到 create 插件的帮助屏幕。

You can check whether it got successfully installed by running serverless create --help. If serverless is successfully installed, you should see the help screen for the create plugin.

install help

请注意,在所有命令中你可以使用简写 sls 代替 serverless

Please note that you can use the shorthand sls instead of serverless in all your commands.

Step 3 − Configure Credentials

你需要从 AWS 获取凭据以配置无服务器配置。为此,要么在 AWS 控制台中创建用户(通过 IAM → 用户 → 添加用户),要么在 IAM → 用户中点击现有用户。如果你创建新用户,则需要附加一些必需的策略(比如 Lambda 访问、S3 访问等),或者为该用户提供管理员访问权限。

You need to obtain credentials from AWS for configuring serverless. For that, either create a user (through IAM → Users → Add user) in the AWS Console or click on an existing User in IAM → Users. If you are creating a new user, you will need to attach some required policies (like Lambda Access, S3 Access, etc.) or provide Administrator access to the user.

set permissions

当你创建用户后,你将能够看到访问秘钥和秘密访问秘钥。请务必将其安全保密。

After you create the user, you will be able to see the access key and secret key. Please keep this very secure and confidential.

secret key

如果你现有的用户,则可以通过执行以下步骤生成新的访问密钥和秘密访问密钥 here

If you are an existing user, you can generate a new Access Key and Secret by following the steps mentioned here.

当你拥有现成的访问密钥和秘密密钥后,你可以使用以下命令在 Serverless 中配置凭证 −

Once you have the access and secret keys handy, you can configure credentials in serverless using the following command −

serverless config credentials --provider aws --key 1234 --secret 5678 --profile custom-profile

profile 区域是可选的。如果你将其留空,则默认配置文件为“aws”。记住你设置的配置文件名,因为在下一教程中我们将看到的 serverless.yml 文件中必须提到它。

The profile field is optional. If you leave it blank, the default profile is 'aws'.Remember what profile name you set because you will have to mention it in the serverless.yml file that we will see in the next tutorial.

如果你已完成上述步骤,则 Serverless 配置已完成。继续阅读下一章,以创建你的第一个 Serverless 项目。

If you’ve completed the above steps, the serverless configuration is complete. Move on to the next chapter to create your first serverless project.