Skip to content

Separate dependency for each layer using a separate requirements.txt file #13384

@dym4dev

Description

@dym4dev

Is there an existing issue for this?

  • I have searched existing issues, it hasn't been reported yet

Use case description

Hello everyone.

After incorporating serverless-python-requirements into the framework, I encountered a problem: there's no way to create separate layers, each with its own dependencies.

Let's say I have three functions:

cognito_post_confirmation - it only needs pydantic
cognito_post_authentication - it only needs ulid
shop - it needs FastAPI, meaning it will automatically install pydantic

To keep size of functions small and uptimize coldstart, my idea was to create three layers:

clear - for functions with minimal packages - only ulid
pydantic - for functions that only require pydantic
fastapi - for functions that require FastaAPI

and I'll include these layers in the corresponding functions.

As far as I know, the serverless-python-requirements plugin allows you to set dependencies for layers. However, in new versions of the serverless framework, it has been integrated into the framework, and now the "layer: true" parameter builds a single dependency layer, uniform for all. Question:

  1. Am I misunderstanding something?
  2. Is there another way to set a separate dependency for each layer using a separate requirements.txt file?

Proposed solution (optional)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions