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

Convert dummy example into a concrete example #36

Open
3 tasks
heitorlessa opened this issue Sep 25, 2020 · 5 comments
Open
3 tasks

Convert dummy example into a concrete example #36

heitorlessa opened this issue Sep 25, 2020 · 5 comments

Comments

@heitorlessa
Copy link
Contributor

Ideas to pick from when time allows:

@kbakk
Copy link

kbakk commented Nov 30, 2021

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)

@heitorlessa
Copy link
Contributor Author

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.

@kbakk
Copy link

kbakk commented Nov 30, 2021

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

@heitorlessa
Copy link
Contributor Author

heitorlessa commented Nov 30, 2021 via email

@marcellodesales
Copy link

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 subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants