Skip to content

invoke local remote layer reuse can fail when local layer exists but cache is missing #244

@GrahamCampbell

Description

@GrahamCampbell

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

  1. Run invoke local with Docker and a remote Lambda layer so both the local layer path and cache path are populated.
  2. Remove the cache directory under cachedir('serverless')/invokeLocal/layers/....
  3. Keep .serverless/layers/<layer>/<version> in place.
  4. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions