Giter Site home page Giter Site logo

Comments (5)

heitorlessa avatar heitorlessa commented on June 28, 2024 3

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.

from cookiecutter-aws-sam-python.

kbakk avatar kbakk commented on June 28, 2024 1

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)

from cookiecutter-aws-sam-python.

kbakk avatar kbakk commented on June 28, 2024

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

from cookiecutter-aws-sam-python.

heitorlessa avatar heitorlessa commented on June 28, 2024

from cookiecutter-aws-sam-python.

marcellodesales avatar marcellodesales commented on June 28, 2024

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.

from cookiecutter-aws-sam-python.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.