My service structure:
-MyService
-common
-node_modules
-functions_folder
-Function1.js
-Function2.js
-Function3.js
yaml file:
service: MyService
provider:
name: aws
runtime: nodejs6.10
stage: dev
functions:
Function1:
handler: functions_folder/Function1.handler
memorySize: 512
timeout: 10
Function2:
handler: functions_folder/Function2.handler
memorySize: 512
timeout: 10
Function2:
handler: functions_folder/Function3.handler
memorySize: 512
timeout: 10
When i’m deploying, i have 3 different lambda functions, but each one contain Function1.js, Function2.js, Function3.js inside.
Can somebody explain me please how to exclude from resulted Lambda not needed files?
Loss Of Control One of the biggest disadvantages of serverless is that you don't have the control over your services. We use a lot of services that are managed by third-party cloud providers, like Cloudwatch for logs and DynamoDB for databases.
The sls package command packages your entire infrastructure into the . serverless directory by default and make it ready for deployment. You can specify another packaging directory by passing the --package option.
To reference environment variables, use the ${env:SOME_VAR} syntax in your serverless. yml configuration file. It is valid to use the empty string in place of SOME_VAR . This looks like " ${env:} " and the result of declaring this in your serverless.
After some time researching i found solution. So here it is:
service: MyService
package:
individually: true
exclude:
- ./**
include:
- common/**
- node_modules/**
provider:
name: aws
runtime: nodejs6.10
stage: dev
memorySize: 512
timeout: 10
functions:
Function1:
handler: functions_folder/Function1.handler
package:
include:
- functions_folder/Function1.js
Function2:
handler: functions_folder/Function2.handler
package:
include:
- functions_folder/Function2.js
Function2:
handler: functions_folder/Function3.handler
package:
include:
- functions_folder/Function3.js
So as you can see in package section i have added include/exclude part, at first i'm excluding all files then i'm include 2 needed folders "common" and "node_modules". After this for each function i also use include command for to add only needed file.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With