Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Powertools for AWS Lambda (Python) v3 #4189

Closed
1 of 2 tasks
leandrodamascena opened this issue Apr 24, 2024 · 17 comments
Closed
1 of 2 tasks

RFC: Powertools for AWS Lambda (Python) v3 #4189

leandrodamascena opened this issue Apr 24, 2024 · 17 comments
Assignees
Labels
RFC v3 Features that will be included in Powertools v3.

Comments

@leandrodamascena
Copy link
Contributor

leandrodamascena commented Apr 24, 2024

Is this related to an existing feature request or issue?

#4067

Which Powertools for AWS Lambda (Python) utility does this relate to?

Other

Summary

We are excited to announce that we are starting a new major version (v3) for Powertools for AWS Lambda (Python). We are expediting a new major version to align with the scheduled Pydantic v1 end-of-life on June 30th, signalling the switch to much anticipated Pydantic v2. Pydantic plays a vital role and we care deeply about supply chain security. This release highlights our dedication to providing a secure and stable library that our customers trust.

Today, we already support both Pydantic v1 and v2. In this new major version, we will make Pydantic v2 the default, removing Pydantic v1. We will take this opportunity to introduce minor breaking changes to address common pain points. As always, we will provide an extensive upgrade guide to make this transition as smooth as possible.

Community

We invite the entire Powertools community, including users and contributors, to actively participate in this RFC. We greatly value the community's contribution, ideas, and willingness to solve problems or validate proposed changes.

Use case

The primary use case is to offer Pydantic v2. That includes a new Lambda Layer for each Python version since Pydantic v2 contains non-Python code (Rust). It future-proof Layers to contain any additional compiled dependency (like cryptography) without a new major version.

Additional key items on v3 backlog

  • Distribute Lambda Layers in the AWS GovCloud regions
  • Return sensible defaults over Optional in Event Source Data Classes to further reduce customers code
  • Remove deprecated code, deprecate legacy code to be removed in v4, and reduce API surface

Proposal

The action plan for this release with scope and tasks is as follows:

  • Update our documentation to comply with our Versioning Policy and inform customers that we have started work on a new major version
  • Create a branch named v3
  • Make adjustments to our GitHub actions to run checks on this new branch
  • Update Powertools v3 milestone to reflect current situation
  • Address and resolve the issues mapped out for the execution of this launch plan.
  • If possible, release early alpha versions for testing

Quick summary (Work in progress - Items can be added or removed):


  • ✅ = done
  • 🚧 = Work in progress
  • 🚫 = Not considered in v3
Item Issue/PR Status Code change required Utility Notes Cross-Language
refactor the SSMProvider class to implement the get_multiple method #3252 Yes Parameters
Return empty Dict or List in Event Source Data Classes instead of None #2605 Yes Event Source Data Class
event_parser envelopes should handle unions of BaseModels #2734 No Parser
Pydantic v2 managed layer #2939 No Layer
Deprecate tracing.base.BaseProvider #4105 🚧 No Tracer
resolved_headers_field is not Optional #4147 No Event Source Data Class
Create a Powertools Lambda layer for each Python version #3859 No Layer
Publish layer to Gov Cloud regions #1166 🚧 No Layer
Remove any specific code for Pydantic v1 #4191 Yes Codebase
Update Powertools documentation to add banner about v3 #4198 No Documentation
Add the aws-encryption-sdk dependency in the Powertools layer #4192 No Layer Depends on #3859
Review the method extract_data_from_envelope in JMESPath Functions #4218 No JMESPath Functions
Split the code from the api_gateway.py file into several other files to ease maintenance #4194 🚫 Yes Event Handler
Add support for v3 branch in the github actions #4220 No CI
Release the new version of Tracer utility with support for external providers #2342 🚧 Yes Tracer
Unmarshal DynamoDB fields when using DynamoDBStreamModel #4219 Yes Parser Reference: #1619
Remove legacy code in the Metrics utility? - 🚫 Yes Metrics Needs discussion
Keep the compatibility with Pydantic v2 and Bedrock agent resolver #4196 🚧 No Event Handler
Change the default TTL (cache) to 5 minutes #4193 Yes Parameters
Update boto3 version to 1.34.32 #4195 No Dependencies
Change behavior to fail batch on first error when using DynamoDB and Kinesis in batch processing NEED ISSUE 🚧 Yes Batch Processing Reference: https://tinyurl.com/yc335m3s
Remove the flag log_uncaught_exceptions in the Logger utility #4199 🚫 Yes Logger See: #1798 (comment)
Support for retrieving batch of secrets #4200 🚧 No Parameters

Deadlines

We plan to release the first version of v3 by the end of June/beginning of July.

Out of scope

We will not include in v3:

  • Modularization to further reduce sizes
  • Strict typing
  • New utilities

Potential challenges

Adding Pydantic v2 in the Powertools layer requires layers per Python version, so the effort to implement this is not yet clear.

Dependencies and Integrations

No response

Alternative solutions

No response

Acknowledgment

@leandrodamascena leandrodamascena added RFC triage Pending triage from maintainers labels Apr 24, 2024
@leandrodamascena leandrodamascena pinned this issue Apr 24, 2024
@leandrodamascena leandrodamascena removed the triage Pending triage from maintainers label Apr 24, 2024
@leandrodamascena leandrodamascena added this to the Powertools v3 milestone Apr 24, 2024
@jplock
Copy link

jplock commented Apr 24, 2024

There's a lot of overlap between the Event Handler, Event Source Data Classes, Parser, and Validation

Is there a nice way to unify it all somehow?

@leandrodamascena leandrodamascena added the v3 Features that will be included in Powertools v3. label Apr 24, 2024
@ran-isenberg
Copy link
Contributor

ran-isenberg commented Apr 26, 2024

There's a lot of overlap between the Event Handler, Event Source Data Classes, Parser, and Validation

Is there a nice way to unify it all somehow?

I agree. Since v3 will use pydantic by default, is there a need to maintain event source data classes? why not move to the parser's pydantic schemas exclusively? I suppose there are some gaps in coverage and missing schemas, but that can be fixed :)
Event handler/validation already support pydantic/parser schemas.

@michaelbrewer
Copy link
Contributor

@jplock @ran-isenberg

i contributed REST API event handler , GraphQL API eventhandler and Event Source Data Classes
as a convenient what to handle AWS built-in event source. The assumption that it would not need any libraries, dependencies or validation as these event come from AWS.

If what can be done here is not a major breaking change or a regression in performance it would be greatly appreciated, as we use Powertools for many internal tools at Fiserv.

@ran-isenberg
Copy link
Contributor

Hey Michael 🙏🏻
I agree, it's a massive breaking change. I'm not sure it's worth it tbh but im biased as i use the parser (and contributed it in the first place). I'll let the good people here decide 🤘

@leandrodamascena
Copy link
Contributor Author

Hey everyone! Thanks for the contribution and for bringing ideas/suggestions to this RFC.

We have no plans to remove features or do extreme refactoring to Powertools V3 utilities/codebase. This release mainly aims to drop Pydantic v1 in favor of v2 and resolve some pain points. When it comes to event source, we will be refactoring and introducing a small breaking change, but still using the same concept of creating objects from events and without any additional dependencies. Removing utilities such as Event Source or making Pydantic mandatory for the Event Handler, for example, could be a huge breaking change and would make it extremely hard for our customers to migrate from v2 to v3.

I agree that we have some overlap between some utilities and could consider merging/removing them, but we can evaluate this in future releases, not in v3.

Thanks

@trallnag
Copy link

trallnag commented Jul 7, 2024

Are you planning to remove the use of parse_obj method? It has been deprecated in v2 and will be completely removed in v3. I am currently using Powertools with Pydantic v2 and I am seeing this warning in my tests:

PydanticDeprecatedSince20: The parse_obj method is deprecated; use model_validate instead. Deprecated in Pydantic V2.0 to be removed in V3.0. See Pydantic V2 Migration Guide at https://errors.pydantic.dev/2.8/migration/

@leandrodamascena
Copy link
Contributor Author

Are you planning to remove the use of parse_obj method? It has been deprecated in v2 and will be completely removed in v3. I am currently using Powertools with Pydantic v2 and I am seeing this warning in my tests:

Hi @trallnag! Yes, we are dropping support for Pydantic v1 and refactoring the code to use the new methods available in Pydantic v2.
Unless there is something very critical that prevents us from achieving this, we are committed to removing any method that is deprecated in v2.

@leandrodamascena
Copy link
Contributor Author

Hello everyone! We are making good progress with V3 and hope to have an alpha release in the next few weeks and then release the official version this month/early September.
Thanks for everyone's patience.

@jesseadams
Copy link

This is exciting! Thanks for the update @leandrodamascena

@zerubeus
Copy link

Hello everyone! We are making good progress with V3 and hope to have an alpha release in the next few weeks and then release the official version this month/early September. Thanks for everyone's patience.

Awesome, thank you!

@leandrodamascena
Copy link
Contributor Author

Hello everyone! We have a first draft of the upgrade guide. This should give you an idea of ​​the changes you will need to make to migrate to v3. We will continue to make changes to this upgrade guide until we launch it.

#5028

@leandrodamascena
Copy link
Contributor Author

Hello everyone! While we are making improvements to the upgrade guide, we already have a development version for local testing or even for your development environment.

We would love to hear your feedback on this new version.

v3.0.0.dev10 - https://pypi.org/project/aws-lambda-powertools/3.0.0.dev10/

Thanks

@github-actions github-actions bot added the pending-release Fix or implementation already in dev waiting to be released label Sep 2, 2024
@Hatter1337
Copy link

Thank you for advancing this product!
I hope this will be the start of improved OpenAPI autogeneration, making it as easy as in FastAPI 😄

@leandrodamascena
Copy link
Contributor Author

Hi @Hatter1337! Thanks for using Powertools and giving us some ideas on what you want to see we investing time into it. But I'm curious about this:

I hope this will be the start of improved OpenAPI autogeneration, making it as easy as in FastAPI 😄

We already support OpenAPI generation in V2. The experience is simple and you just need to write down your routes and access swagger or generate OpenAPI JSON Schema.

https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#openapi

Are you talking about something different? Any improvement? I'm really curious to hear from you.

@Hatter1337
Copy link

Hi @Hatter1337! Thanks for using Powertools and giving us some ideas on what you want to see we investing time into it. But I'm curious about this:

I hope this will be the start of improved OpenAPI autogeneration, making it as easy as in FastAPI 😄

We already support OpenAPI generation in V2. The experience is simple and you just need to write down your routes and access swagger or generate OpenAPI JSON Schema.

https://docs.powertools.aws.dev/lambda/python/latest/core/event_handler/api_gateway/#openapi

Are you talking about something different? Any improvement? I'm really curious to hear from you.

This might not be the best place for this discussion, but I’ll respond here...

I've been using Powertools for quite long time, and to be honest, I often end up writing the Swagger file manually, primarily because OpenAPI generation requires almost full descriptions:

@router.get(
    "/user/<id>",
    summary="Get user data",
    description="Get user data from ...",
    response_description="User data",
    responses={
        200: {
            "description": "Success",
            "content": {"application/json": {"model": UserDataResponse}},
        },
        400: {
            "description": "Bad request",
            "content": {"application/json": {"model": BadRequestResponse}},
        },
        404: {
            "description": "Not found",
            "content": {"application/json": {"model": NotFoundResponse}},
        },
    },
    tags=["User"],
)

All of this is in the same file as the business logic, making it quite bulky and harder to manage. I'm not sure how it's implemented in FastAPI, but there it seems much simpler 🙊

Occasionally, I run into certain issues, one of which I've described here. Another example is that I haven’t been able to find information on how to add something similar to this when using app.enable_swagger:

@app.get("/swagger", include_in_schema=False)
def openapi():
    return app.get_openapi_json_schema(
        title="Awesome API",
        servers=[servers],
        security_schemes={
            "apikey": APIKey(
                name="X-API-KEY",
                description="API KeY",
                in_=APIKeyIn.header,
            ),
        },
    )

Also, I prefer to split API endpoints across different Lambda functions - for example, having User CRUD in one Lambda function and authentication in another, rather than putting the entire API in a single Lambda function. However, with this approach, it's almost impossible to generate a unified OpenAPI/Swagger file for the whole API.


That said, I still believe Powertools is an amazing framework, and I'm grateful to everyone who contributed to its development. I hope I can also be helpful to the community in the future.

@zerubeus
Copy link

Where can we find the new doc for V3?

Copy link
Contributor

This is now released under 3.0.0 version!

@github-actions github-actions bot removed the pending-release Fix or implementation already in dev waiting to be released label Sep 23, 2024
@leandrodamascena leandrodamascena unpinned this issue Sep 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFC v3 Features that will be included in Powertools v3.
Projects
Status: Coming soon
Development

No branches or pull requests