【问题标题】:Problem when deploying a NodeJS function using Serverless Framework使用无服务器框架部署 NodeJS 函数时出现问题
【发布时间】:2018-12-26 19:22:39
【问题描述】:

我有一个具有这种架构的应用程序:

-Function1
  .index.js
-Function2
  .index.py
  .requirements.txt
-Function3
  .index.py
  .requirements.txt
-Function4
  .index.py
  .requirements.txt
-node_modules
.serverless.yml
.package.json

我的问题是当我调用 serverless deploy 我最终在 NodeJS 函数 (Function1) 中得到了整个应用程序

这个问题只发生在 NodeJS 函数上,Python 函数只有每个函数相关的代码。

注意:我的 serverless.yml 中有这个:

package:
  individually: true
plugins:
  - serverless-python-requirements
  - serverless-iam-roles-per-function
  - serverless-pseudo-parameters
  - serverless-plugin-include-dependencies

感谢您的帮助。

【问题讨论】:

    标签: node.js amazon-web-services serverless-framework


    【解决方案1】:

    我将 /typescript/es7 用于无服务器功能,请在 serverless.yml 中尝试:

    plugins:
    - ...
      - ...
    
    provider:
    
    
    name: aws
      runtime: **nodejs8.10**
      stage: ...
      profile: ...
      region: ...
    
    functions:
      [function name]:
        handler: function1/index.js
        events:
          - http:
              method: get
              ...
    

    【讨论】:

    • 您的应用程序中是否也有 python 函数?
    • 不,但是如果你想在你的项目中同时使用 node.js 和 python,我建议你使用 docker。 blog.morizyun.com/blog/…
    【解决方案2】:

    解决方案是在 serverless.yml 中使用 Exclude / Include 命令

    所以我刚刚添加了:

    package:
      exclude:
        - ./**
      include:
        - CreateThumbnail/index.handler
        - node_modules/**
    

    现在NodeJS函数只包含nodes模块依赖和函数源码。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-07
      • 2022-12-09
      • 2021-01-26
      • 2022-01-23
      • 2021-06-08
      • 2020-01-01
      • 2019-03-02
      • 1970-01-01
      相关资源
      最近更新 更多