Summary
invoke local remote layer handling can fail if the local extracted layer directory exists but the cached layer directory has been removed.
In lib/plugins/aws/invoke-local/index.js, getLayerPaths() checks whether the local layer contents path exists. If it does, the cache path is not checked or repopulated. However, the code still unconditionally copies from the cache path to the local layer path afterward.
If the OS cache directory was cleared independently, this can throw ENOENT.
Affected Logic
getLayerPaths() remote layer flow:
- Checks
.serverless/layers/<layer>/<version>
- Skips cache validation/download if that local path exists
- Still calls
copy(layerContentsCachePath, layerContentsPath)
Reproduction Scenario
- Run
invoke local with Docker and a remote Lambda layer so both the local layer path and cache path are populated.
- Remove the cache directory under
cachedir('serverless')/invokeLocal/layers/....
- Keep
.serverless/layers/<layer>/<version> in place.
- Run
invoke local again.
Expected Behavior
If the local layer contents path already exists, getLayerPaths() should return it without requiring the cache path to exist.
Actual Behavior
The function attempts to copy from the missing cache path and can fail with ENOENT.
Suggested Fix
When layerContentsPath exists, return it immediately instead of copying from layerContentsCachePath.
The existing unit test named uses existing local remote layer contents without SDK lookup or download should also assert that copy() is not called in this case.
Summary
invoke localremote layer handling can fail if the local extracted layer directory exists but the cached layer directory has been removed.In
lib/plugins/aws/invoke-local/index.js,getLayerPaths()checks whether the local layer contents path exists. If it does, the cache path is not checked or repopulated. However, the code still unconditionally copies from the cache path to the local layer path afterward.If the OS cache directory was cleared independently, this can throw
ENOENT.Affected Logic
getLayerPaths()remote layer flow:.serverless/layers/<layer>/<version>copy(layerContentsCachePath, layerContentsPath)Reproduction Scenario
invoke localwith Docker and a remote Lambda layer so both the local layer path and cache path are populated.cachedir('serverless')/invokeLocal/layers/.....serverless/layers/<layer>/<version>in place.invoke localagain.Expected Behavior
If the local layer contents path already exists,
getLayerPaths()should return it without requiring the cache path to exist.Actual Behavior
The function attempts to copy from the missing cache path and can fail with
ENOENT.Suggested Fix
When
layerContentsPathexists, return it immediately instead of copying fromlayerContentsCachePath.The existing unit test named
uses existing local remote layer contents without SDK lookup or downloadshould also assert thatcopy()is not called in this case.