Fix: deploy layers when hot reload enabled #222
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Layers are not deployed if hot reloading is enabled through
mountCode: true
. In the Serverless AWS provider, Lambda functions and layers are deployed together (uploadFunctionsAndLayers
) but serverless-localstack has currently many limitations with hot reloading (e.g., global config, no layer support). This PR provides a workaround to unblock customers who want to hot-reload functions and regularly deploy layers.Root cause
Hot reloading (i.e., mountCode) in serverless-localstack breaks any Lambda layers with the new Lambda provider:
When trying to deploy a Lambda function with a layer, it fails with an OperationalError:
When mountCode is enabled, layers do not get packaged and deployed:
Skip plugin function Package.packageService (lambda.mountCode flag is enabled)
Therefore, the deployment fails.
Challenges
mountCode: true
is a global option but currently does not support hot-reloading of layers (new feature in LocalStack 2.0).mountCode
is bad terminology because the current implementation does not do any mounting anymore but rather copies ZIP files (https://docs.localstack.cloud/user-guide/tools/lambda-tools/hot-reloading/).hotReload
would be a better namemountCode: true
uses the current directory (assumed to be project directory) as default hot reload path or accepts relative paths (e.g., ./functions). This might lead to many unnecessary reloads.Background
this.skipIfMountLambda('AwsDeploy', 'uploadFunctionsAndLayers');
disables layer uploading, which happens together with functionsthis.skipIfMountLambda('Package', 'packageService');
disables packaging in generaladdPropertiesToSchema
to add something likedefineLayerProperties
?! Might need to relax provider schema by allowing additional properties like for functions.patternProperties here https://github.com/serverless/serverless/blob/ed15cb27aee68954c93d875da96274914943ad71/lib/classes/config-schema-handler/index.js#L335Workaround
Removing the skipIfMountLambda circumvents the issue at the expense of slower initial deployment (with potential other deployment-related side-effects):
this.skipIfMountLambda('Package', 'packageService');
this.skipIfMountLambda('AwsDeploy', 'uploadFunctionsAndLayers');
Testing
layer_problem
(shared in Pro support)serverless-python-requirements
plugin where dependencies are packaged as layer (but slow due to default root directory)Side-effects
To fix this issue, we need to think about a new fine-grained API for hot reloading and handle selective deployments of all layers and functions that are not hot reloading.
Questions
AwsCompileFunctions.downloadPackageArtifacts
⇒ package (i.e., can we safely skip packaging withoutdownloadPackageArtifacts
?