|
4 | 4 | [](https://badge.fury.io/py/pypwext)
|
5 | 5 | [](https://sonarcloud.io/dashboard?id=pypwext)
|
6 | 6 |
|
| 7 | +This is a extension, decorators and other utilities that complements thew [AWS Lambda Powertools](https://awslabs.github.io/aws-lambda-powertools-python) library. It is centered around the following four **pillars** |
7 | 8 |
|
8 |
| -PyPi(https://pypi.org/project/pypwext/) |
9 | 9 |
|
| 10 | +1. Logging |
| 11 | +```python |
| 12 | +logger = PyPwExtLogger() |
| 13 | + |
| 14 | +@logger.method(classification=InfoClassification.PII) |
| 15 | +def subscribe(customer: Customer) -> Subscription: |
| 16 | + ... |
| 17 | +``` |
| 18 | +2. Error handling |
| 19 | +```python |
| 20 | +errors = PyPwExtErrorHandler() |
| 21 | + |
| 22 | +@errors.collect |
| 23 | +def do_operation(): |
| 24 | + raise PyPwExtHTTPError('Something went wrong', details={'foo': 'bar'}) |
| 25 | +``` |
| 26 | +3. HTTP and Lambda Communication |
| 27 | +```python |
| 28 | +http = PyPwExtHTTPSession() # Defaults with "sane" retries, exp back-off etc. |
| 29 | + |
| 30 | +@http.method( |
| 31 | + method='POST', |
| 32 | + url='https://{STAGE}.execute-api.{AWS_REGION}.amazonaws.com/{api_version}/my-api' |
| 33 | + params= {'email':'{email}'}, |
| 34 | + body='customer' |
| 35 | +) |
| 36 | +def send_offer( |
| 37 | + api_version:str, |
| 38 | + email: str, |
| 39 | + customer: Customer, |
| 40 | + response_code:HTTPStatus=HTTPStatus.OK, |
| 41 | + response_body:str = '' |
| 42 | +) -> str: |
| 43 | + ... |
| 44 | +``` |
| 45 | +4. µService Support |
| 46 | +```python |
| 47 | +service = PyPwExtService() |
| 48 | + |
| 49 | +@service.response |
| 50 | +@event_parser(model=Order) |
| 51 | +def handler(event: Order, context: LambdaContext): |
| 52 | + |
| 53 | + if not event.pypwext_id: |
| 54 | + raise StdPyPwExtError( |
| 55 | + code=HTTPStatus.BAD_REQUEST, |
| 56 | + message="Missing pypwext_id", |
| 57 | + ) |
| 58 | + |
| 59 | + return PyPwExtResponse( |
| 60 | + status_code=HTTPStatus.OK, |
| 61 | + updated=[item for item in event.items], |
| 62 | + operation="create-order", |
| 63 | + ) |
| 64 | +``` |
| 65 | + |
| 66 | + |
| 67 | +## Overview |
10 | 68 | This module contains the core functionality of the PyPwExt µService applications.
|
11 | 69 |
|
12 | 70 | :bulb: Each piece of functionality is implemented as an individual function and is **not**
|
|
0 commit comments