
- Serverless 教程
- Serverless - 首页
- Serverless - 简介
- Serverless - 安装
- Serverless - 部署函数
- Serverless - 区域、内存大小、超时时间
- Serverless - 服务
- Serverless - 定时 Lambda 函数
- Serverless - API Gateway 触发的 Lambda 函数
- Serverless - 包含/排除
- Serverless - 插件
- Serverless - 打包依赖项
- Serverless - 层创建
- Serverless - 使用 DynamoDB 的 REST API
- Serverless - Telegram 回声机器人
- Serverless 有用资源
- Serverless - 快速指南
- Serverless - 有用资源
- Serverless - 讨论
Serverless - 安装
Serverless 的安装已经在另一个 Tutorialspoint 教程中介绍过。这里对它进行了一些修改和补充。
步骤 1 - 安装 nodejs
首先,您需要安装 nodejs。您可以通过打开命令提示符并键入 **node -v** 来检查您的机器上是否已安装 nodejs。如果已安装,您将获得 node 的版本号。否则,您可以从此处下载并安装 node:[https://node.org.cn/en/download/](https://node.org.cn/en/download/)

步骤 2 - 使用 npm 命令安装 serverless
您可以使用以下命令安装 serverless(npm 代表 node 包管理器):
npm install -g serverless
您可以通过运行 **serverless create --help** 来检查它是否已成功安装。如果 serverless 成功安装,您应该会看到 create 插件的帮助屏幕。

请注意,您可以在所有命令中使用简写 **sls** 代替 **serverless**。
Explore our latest online courses and learn new skills at your own pace. Enroll and become a certified expert to boost your career.
步骤 3 - 配置凭证
您需要从 AWS 获取凭证才能配置 serverless。为此,您可以在 AWS 控制台中创建一个用户(通过 IAM -> 用户 -> 添加用户),或者单击 IAM -> 用户中现有的用户。如果您正在创建一个新用户,则需要附加一些必需的策略(例如 Lambda 访问、S3 访问等)或向用户提供管理员访问权限。

创建用户后,您将能够看到访问密钥和密钥。请妥善保管这些密钥,并将其保密。

如果您是现有用户,您可以按照此处提到的步骤生成新的访问密钥和密钥:[https://docs.aws.amazon.com/powershell/latest/userguide/pstools-appendix-sign-up.html](https://docs.aws.amazon.com/powershell/latest/userguide/pstools-appendix-sign-up.html)
准备好访问密钥和密钥后,您可以使用以下命令在 serverless 中配置凭证:
serverless config credentials --provider aws --key 1234 --secret 5678 --profile custom-profile
profile 字段是可选的。如果您将其留空,则默认配置文件为“aws”。请记住您设置的配置文件名称,因为您需要在下一个教程中看到的 serverless.yml 文件中提及它。
如果您已完成上述步骤,则 serverless 配置已完成。继续下一章,创建您的第一个 serverless 项目。