问题
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