Sometimes you might like to have more control over your function artifacts and how they are packaged.
You can use the
exclude configuration for more control over the packaging process.
Exclude and include allows you to define globs that will be excluded / included from the resulting artifact. If you wish to
include files you can use a glob pattern prefixed with
! such as
exclude or the dedicated
Serverless will run the glob patterns in order.
At first it will apply the globs defined in
exclude. After that it'll add all the globs from
include. This way you can always re-include
previously excluded files and directories.
Exclude all node_modules but then re-include a specific modules (in this case node-fetch) using
package: exclude: - node_modules/** - '!node_modules/node-fetch/**'
Exclude all files but
package: exclude: - src/** include: - src/function/handler.js
Note: Don't forget to use the correct glob syntax if you want to exclude directories
exclude: - tmp/** - .git/**
For complete control over the packaging process you can specify your own artifact zip file.
Serverless won't zip your service if this is configured and therefore
include will be ignored. Either you use artifact or include / exclude.
The artifact option is especially useful in case your development environment allows you to generate a deployable artifact like Maven does for Java.
service: my-service package: exclude: - tmp/** - .git/** include: - some-file artifact: path/to/my-artifact.zip
If you want even more controls over your functions for deployment you can configure them to be packaged independently. This allows you more control for optimizing your deployment. To enable individual packaging set
individually to true in the service wide packaging settings.
Then for every function you can use the same
artifact config options as you can service wide. The
include option will be merged with the service wide options to create one
include config per function during packaging.
service: my-service package: individually: true exclude: - excluded-by-default.json functions: hello: handler: handler.hello package: # We're including this file so it will be in the final package of this function only include: - excluded-by-default.json world: handler: handler.hello package: exclude: - some-file.js