[Python] How to structure a Serverless Framework project with a root serverless.yml and...

Discussão em 'Python' iniciado por Stack, Junho 2, 2025.

  1. Stack

    Stack Membro Participativo

    I'm working on a Python project using FastAPI, AWS Lambda, and API Gateway. I'm organizing my project with a root serverless.yml and separate serverless.yml files inside each function's folder.

    When I try to deploy, I get the following error:


    Cannot resolve '${file(./service/../serverless.yml)}' variable at 'functions.0'. No value is available for this variable, and no default value was provided. Please check your variable definitions or provide a default value
    ​

    root/
    │
    ├── serverless.yml # root
    ├── service/
    │ └── post_event/
    │ ├── serverless.yml # function-level
    │ └── main.py


    In the root serverless.yml, I tried referencing the function-specific config like this:

    functions:
    - ${file(./service/post_event/serverless.yml)}`


    In service/post_event/serverless.yml, I defined the function like so:

    postEvent:
    name: ${self:service}-${opt:stage, self:provider.stage}-postEvent
    handler: service.post_event.main.handler
    module: service/publish_event`


    I expected this structure to work by allowing each function to have its own serverless.yml and keeping the root file cleaner, but deployment fails with the error above.

    Continue reading...

Compartilhe esta Página