Skip to content
This repository was archived by the owner on May 19, 2024. It is now read-only.
This repository was archived by the owner on May 19, 2024. It is now read-only.

Convert dummy example into a concrete example #36

Open

Description

@heitorlessa

Ideas to pick from when time allows:

Activity

  1. kbakk commented on Nov 30, 2021

    @kbakk

    A few examples on things I find difficult which I think can help others:

    • Multiple Lambda functions (could be an idea to show how to use two different functions in the same module, as well as two completely standalone modules)
    • Some shared library that all functions uses (showcasing layers)
    • Lambda function with additional modules (in app.py e.g. from my_module import my_func)
  2. heitorlessa commented on Nov 30, 2021

    @heitorlessa
    ContributorAuthor

    hey @kbakk thank you so much for that. Now that Powertools has a Router functionality, @michaelbrewer and I have been discussing revamping this with two options: Monolithic and Micro function - both with shared and Lambda Layer (build optimization + dev dependency).

    https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/api_gateway/#considerations

    The monolithic option would take an hour to add since we already have a good project structure that works in both PyCharm and VSCode. The latter requires an additional CLI (e.g. PyInvoke) to support building separate functions while supporting relative and absolute imports, since SAM CLI discards the top level directory - the latter also needs additional cycles to ensure C bindings are built within a Docker Container.

  3. kbakk commented on Nov 30, 2021

    @kbakk

    You may want to look into Poetry. I'm experimenting with this currently:

    [tool.poetry]
    # ...
    packages = [
        { include = "my_app_dir", from = "functions/my_app_dir" },
        { include = "tests" }
    ]

    This creates a .pth in the site-packages folder, I believe this is similar to modifying PYTHONPATH (for the local dev-environment).

    cat $(poetry env info -p)/lib/python3.9/site-packages/my_project.pth
    ~/Code/my_project
    ~/Code/my_project/functions/my_app_dir
    

    My handler is in functions/my_app_dir/my_app_dir/lambda_handler. The double-dir is to be able to say import my_app_dir.sub_module in the Lambda handler.

      MyLogicFn:
        Type: AWS::Serverless::Function
        Properties:
          CodeUri: functions/my_app_dir
          Handler: my_app_dir.lambda_handler.create_asset
  4. heitorlessa commented on Nov 30, 2021

    @heitorlessa
    ContributorAuthor
  5. marcellodesales commented on Sep 29, 2022

    @marcellodesales

    Hi @heitorlessa, do you have any update on this? I'd like to see both approaches you described at your comments...

    hey @kbakk thank you so much for that. Now that Powertools has a Router functionality, @michaelbrewer and I have been discussing revamping this with two options: Monolithic and Micro function - both with shared and Lambda Layer (build optimization + dev dependency).

    https://awslabs.github.io/aws-lambda-powertools-python/latest/core/event_handler/api_gateway/#considerations

    The monolithic option would take an hour to add since we already have a good project structure that works in both PyCharm and VSCode. The latter requires an additional CLI (e.g. PyInvoke) to support building separate functions while supporting relative and absolute imports, since SAM CLI discards the top level directory - the latter also needs additional cycles to ensure C bindings are built within a Docker Container.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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