Middleware Factory
Utilities to enhance middleware
Usage Documentation
MODULE | DESCRIPTION |
---|---|
exceptions |
|
factory |
|
FUNCTION | DESCRIPTION |
---|---|
lambda_handler_decorator |
Decorator factory for decorating Lambda handlers. |
lambda_handler_decorator ¶
lambda_handler_decorator(
decorator: Callable | None = None,
trace_execution: bool | None = None,
) -> Callable
Decorator factory for decorating Lambda handlers.
You can use lambda_handler_decorator to create your own middlewares,
where your function signature follows: fn(handler, event, context)
Custom keyword arguments are also supported e.g. fn(handler, event, context, option=value)
Middlewares created by this factory supports tracing to help you quickly troubleshoot any overhead that custom middlewares may cause - They will appear as custom subsegments.
Non-key value params are not supported e.g. fn(handler, event, context, option)
Environment variables
POWERTOOLS_TRACE_MIDDLEWARES : str
uses aws_lambda_powertools.tracing.Tracer
to create sub-segments per middleware (e.g. "true", "True", "TRUE"
)
PARAMETER | DESCRIPTION |
---|---|
decorator
|
Middleware to be wrapped by this factory
TYPE:
|
trace_execution
|
Flag to explicitly enable trace execution for middlewares.
TYPE:
|
Example
Create a middleware no params
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Create a middleware with params
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Trace execution of custom middleware
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Limitations
- Async middlewares not supported
- Classes, class methods middlewares not supported
RAISES | DESCRIPTION |
---|---|
MiddlewareInvalidArgumentError
|
When middleware receives non keyword=arguments |
Source code in aws_lambda_powertools/middleware_factory/factory.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|
exceptions ¶
CLASS | DESCRIPTION |
---|---|
MiddlewareInvalidArgumentError |
When middleware receives non keyword=arguments |
factory ¶
FUNCTION | DESCRIPTION |
---|---|
lambda_handler_decorator |
Decorator factory for decorating Lambda handlers. |
lambda_handler_decorator ¶
lambda_handler_decorator(
decorator: Callable | None = None,
trace_execution: bool | None = None,
) -> Callable
Decorator factory for decorating Lambda handlers.
You can use lambda_handler_decorator to create your own middlewares,
where your function signature follows: fn(handler, event, context)
Custom keyword arguments are also supported e.g. fn(handler, event, context, option=value)
Middlewares created by this factory supports tracing to help you quickly troubleshoot any overhead that custom middlewares may cause - They will appear as custom subsegments.
Non-key value params are not supported e.g. fn(handler, event, context, option)
Environment variables
POWERTOOLS_TRACE_MIDDLEWARES : str
uses aws_lambda_powertools.tracing.Tracer
to create sub-segments per middleware (e.g. "true", "True", "TRUE"
)
PARAMETER | DESCRIPTION |
---|---|
decorator
|
Middleware to be wrapped by this factory
TYPE:
|
trace_execution
|
Flag to explicitly enable trace execution for middlewares.
TYPE:
|
Example
Create a middleware no params
1 2 3 4 5 6 7 8 9 10 11 12 |
|
Create a middleware with params
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
|
Trace execution of custom middleware
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Limitations
- Async middlewares not supported
- Classes, class methods middlewares not supported
RAISES | DESCRIPTION |
---|---|
MiddlewareInvalidArgumentError
|
When middleware receives non keyword=arguments |
Source code in aws_lambda_powertools/middleware_factory/factory.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
|