如何将 Serverless 0.X 中的 "project" 迁移到 Serverless 1.0?

How to migrate "project" in Serverless 0.X to Serverless 1.0?

我曾经使用过 Serverless 0.X 框架,并且有一些自己的项目使用它。之后有半年左右的空白期,又回到Serverless 1.0

在Serverless 0.X中,我们有"project"的概念,可以在同一个环境下处理很多功能。但是在 Serverless 1.X 中,"project" 看起来已经退休了,根文件夹下只有一个 "handler.js"。

如何在同一环境下处理多个功能?我应该在一个 handler.js 中编写所有函数吗?

以及如何避免每个函数的 50MB 限制?在Serverless0.X中很容易避开这个限制,因为每个函数都是单独上传的,但是我不知道如何在Serverless1.X.

中避开这个限制

包括这些问题,是否有将 Serverless 0.X 项目迁移到 Serverless 1.X 的好文档?

From official docs:

How to upgrade from 0.x to 1.x

As Serverless 1.x is a complete reimplementation and does not implement all the features that were in 0.x (but has a lot more features in general) there is no direct update path. Basically the best way for users to move from 0.x to 1.x is to go through our guide and the AWS provider documentation that will teach you all the details of Serverless 1.x. This should make it pretty easy to understand how to set up a service for 1.x and move your code over. We've worked with different teams during the Beta phase of Serverless 1.x and they were able to move their services into the new release pretty quickly.

现在,回答您的问题:

How can I handle many functions under same environment? Should I code all functions within one handler.js?

您需要阅读这篇关于无服务器架构的 blog post。答案是您不需要只使用一种功能。你可以有多个函数。此外,handler.js 文件不需要具有此名称,也不需要位于根文件夹中。请参阅以下 serverless.yml 示例。

service: my-storage

provider:
  name: aws
  runtime: nodejs4.3

functions:
  my-photos:
    handler: lib/photos.handlePhotos
    events:
      - http: GET photos
      - http: POST photos
      - http: PUT photos
      - http: DELETE photos
      - http: OPTIONS photos
  my-videos:
    handler: lib/videos.handleVideos
    events:
      - http: GET videos
      - http: POST videos
      - http: PUT videos
      - http: DELETE videos
      - http: OPTIONS videos

在此示例中,我们在 lib 文件夹中有两个文件:photos.jsvideos.js。每个文件都有一个函数 (handlePhotos / handleVideos) 负责处理 API 网关事件。

And how can I avoid 50MB limits of each functions?

使用多项功能。