Skip to content

Feature: Create your own middleware #20

Closed

Description

@heitorlessa

As we prepare for GA, we need to reduce the effort in creating new middlewares, and ensure any middleware is traced opt in. This would help us move faster in creating more utilities, allow customers to create their own utilities (outside of this package), and debug middleware performance as they use multiple nested options.

This feature should allow:

  • Decorator to create middlewares
  • Control before, after, handle exceptions, and whether handler should be executed if they want to
  • Opt in option to trace middleware as an annotation with no modification to their code
  • Pass data between middlewares (e.g. correlation id, cold_start, etc.)

We have to decide between two options to pass data between middlewares:

  • Lambda Context
    • Pros: Ease to extend and available between middlewares, no additional code to maintain
    • Cons: There could be naming collision if Lamda decides to use context more extensively, each middleware needs to handle AttributeError if key is not there
  • Global Stash
    • Pros: Available anywhere in the code and handles AttributeError if data is non existent
    • Cons: Additional code to maintain

Activity

  1. self-assigned this
    on Apr 14, 2020
  2. nmoutschen commented on Apr 14, 2020

    @nmoutschen
    Contributor

    I'd prefer to use a global stash, separate from the Lambda context variable as the Lambda service team might want to make changes to the context that would be backward compatible with Lambda, but could break compatibility with the powertools, thus requiring work both here and for users of this library.

    E.g. if this provides an additional cold_start attribute to the context, but in the future the Lambda service team decides to add that as part of the Lambda context, this would hide the original value.

    In a worst case scenario, the value provided by the Lambda team could be presented differently than from powertools. E.g. if the powertools provides context.cold_start as a boolean (true/false), but then Lambda provides it as a string ("true"/"false"), "false" is a truthy value and therefore changing the behaviour in the powertools to expose the Lambda's context value would be a breaking change.

  3. heitorlessa commented on Apr 20, 2020

    @heitorlessa
    ContributorAuthor

    Now merged on 0.7.0 🎉

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

Metadata

Metadata

Assignees

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