Serverless Framework with custom packaging

本小妞迷上赌 提交于 2019-12-24 08:23:20

问题


I'm using the Serverless Framework and I can't seem to package my functions the way I want.

My current folder directory looks like this:

service/
  serverless.yml
  function1/
    package.json
    handler.js
    node_modules/
      ...
  function2/
    handler.py
    requirements.txt
    venv/
      ...

Is it possible to cherry pick which folder I want to include in the zip file and also specify the corresponding destination path inside the zip file?

For example, I want to zip everything inside function1 folder but all of them should be at root level of the zip file. Right now all the generated files are in a folder called function1 in the zip file.


回答1:


Packaging does not work this way (docs). You can't specify the file tree that will be saved inside the zip. You can only specify what you will include or exclude in this zip.

In the docs link, you can see an option to use an Artifact. In this case, you could develop your own code to zip using exactly the rules that you want and output a zip file to be used by the Serverless Framework. It is possible, but I hope that you don't need this.

Why do you want to move the contents of the folder "function1" to the root level? Maybe your true question is: "How can I reference my Lambda function that is located at another folder?". If this is the case, you could use the following in the serverless.yml file:

service: test

functions:
  func1:
    handler: function1/handler.func1
  func2:
    handler: function1/handler.func2

The syntax is folder/filename.function.

Another solution would be to create one serverless.yml file for each folder. The problem with this approach is that you would not be able to access the function2 from the function1.



来源:https://stackoverflow.com/questions/42415688/serverless-framework-with-custom-packaging

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!