AWS Deploy 无服务器限制?
AWS Deploy Serverless limit?
我有一个无服务器项目,它有很多 API 个端点,当我尝试一次部署所有端点时,出现此错误:
错误:CloudFormation 模板无效:模板格式错误:资源数量 293 大于允许的最大值 200
在 C:...\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deplow\lib\validateTemplate.js:20:13
我的 serverless.yaml 函数 def 看起来像这样
functions:
# Auth: Sign-in
signIn:
handler: src/collections/auth/auth.signIn
events:
- http:
path: auth/signIn
method: post
cors: true
# Admin-User: Find Permission By Role
findPermissionByRole:
handler: src/collections/permissions/permissions.findPermissionByRole
events:
- http:
path: permissions/findPermissionByRole
method: get
cors: true
# Lookup: FindAll
lookup:
handler: src/collections/lookup/lookup.find
events:
- http:
path: lookup/find
method: post
cors: true
...(1180 lines of code 131 resources)
有 131 个 Handler/events - 但如果我尝试部署超过 20(二十)个,我就会收到该错误。
所以我对指定 293 的错误消息感到困惑,当我有 131 时指定最大 200。
对此有什么想法吗?
此问题是由于 Cloudformation API 中的以下 limit:
记住,serverless 可以添加 up to 6 resources 到 CloudFormation 请求
For each http event you configured, you end up creating six (!)
CloudFormation resources, in addition to shared resources like
AWS::ApiGateway::RestApi and AWS::IAM::Role.
为了解决这个问题,serverless 建议 one of the following:
- 分解您的 API :选择小型部署和小型代码(按业务领域划分)。但这对于现有项目可能需要很多。
- 在您的应用程序逻辑中处理路由:将由 API 网关完成的一些繁重工作改为由 lambda 函数完成。
- 使用插件将您的服务分成多个堆栈或 nested stacks: Use this neat AWS solution for the 200 resource limit in one cloudformation template. (e.g. serverless-plugin-split-stacks, serverless-plugin-additional-stacks ... 等等)
- 向 AWS 请求增加 CloudFormation 限制:不会解决根本原因,只会解决它直到您的应用程序变得更大并且 运行 陷入同样的问题但是更高的限制和更多的 complex/bigger 代码。
我有一个无服务器项目,它有很多 API 个端点,当我尝试一次部署所有端点时,出现此错误:
错误:CloudFormation 模板无效:模板格式错误:资源数量 293 大于允许的最大值 200 在 C:...\AppData\Roaming\npm\node_modules\serverless\lib\plugins\aws\deplow\lib\validateTemplate.js:20:13
我的 serverless.yaml 函数 def 看起来像这样
functions:
# Auth: Sign-in
signIn:
handler: src/collections/auth/auth.signIn
events:
- http:
path: auth/signIn
method: post
cors: true
# Admin-User: Find Permission By Role
findPermissionByRole:
handler: src/collections/permissions/permissions.findPermissionByRole
events:
- http:
path: permissions/findPermissionByRole
method: get
cors: true
# Lookup: FindAll
lookup:
handler: src/collections/lookup/lookup.find
events:
- http:
path: lookup/find
method: post
cors: true
...(1180 lines of code 131 resources)
有 131 个 Handler/events - 但如果我尝试部署超过 20(二十)个,我就会收到该错误。 所以我对指定 293 的错误消息感到困惑,当我有 131 时指定最大 200。
对此有什么想法吗?
此问题是由于 Cloudformation API 中的以下 limit:
记住,serverless 可以添加 up to 6 resources 到 CloudFormation 请求
For each http event you configured, you end up creating six (!) CloudFormation resources, in addition to shared resources like AWS::ApiGateway::RestApi and AWS::IAM::Role.
为了解决这个问题,serverless 建议 one of the following:
- 分解您的 API :选择小型部署和小型代码(按业务领域划分)。但这对于现有项目可能需要很多。
- 在您的应用程序逻辑中处理路由:将由 API 网关完成的一些繁重工作改为由 lambda 函数完成。
- 使用插件将您的服务分成多个堆栈或 nested stacks: Use this neat AWS solution for the 200 resource limit in one cloudformation template. (e.g. serverless-plugin-split-stacks, serverless-plugin-additional-stacks ... 等等)
- 向 AWS 请求增加 CloudFormation 限制:不会解决根本原因,只会解决它直到您的应用程序变得更大并且 运行 陷入同样的问题但是更高的限制和更多的 complex/bigger 代码。