You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+127
Original file line number
Diff line number
Diff line change
@@ -29,10 +29,137 @@ A suite of Python utilities for AWS Lambda functions to ease adopting best pract
29
29
***[Idempotency](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/idempotency/)** - Convert your Lambda functions into idempotent operations which are safe to retry
30
30
***[Feature Flags](https://awslabs.github.io/aws-lambda-powertools-python/latest/utilities/feature_flags/)** - A simple rule engine to evaluate when one or multiple features should be enabled depending on the input
31
31
32
+
32
33
### Installation
33
34
34
35
With [pip](https://pip.pypa.io/en/latest/index.html) installed, run: ``pip install aws-lambda-powertools``
35
36
37
+
## Quick Start
38
+
With [SAM](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) installed create, hello-world application and instruct it to include powertools library in the runtime.
39
+
```sh
40
+
sam init --runtime python3.9 --dependency-manager pip --app-template hello-world --name sam-app
Copy following code into `sam-app/hello-world/app.py`. Build the package and invoke our Lambda code locally `sam build && sam local invoke HelloWorldFunction -e events/event.json`
45
+
```python
46
+
from aws_lambda_powertools import Logger
47
+
48
+
logger = Logger()
49
+
50
+
51
+
defsend_message(message: str):
52
+
logger.info(f"Message returned: {message}")
53
+
return {"message": message}
54
+
55
+
56
+
@logger.inject_lambda_context(log_event=True)
57
+
deflambda_handler(event, context):
58
+
return send_message(message="hello")
59
+
60
+
```
61
+
62
+
As a result we should see two records in our logs following the same structured pattern. First one includes the whole event and context thanks to `inject_lambda_context` decorator. Second is the result of invoking `logger.info method`
if you deploy this changes into your account those logs will be picked up by cloudwatch and corresponding metrics will be generated
125
+
``sam build && sam deploy``
126
+
Metrics:
127
+
<screenshot>
128
+
129
+
130
+
## Event Handler for Amazon API Gateway:
131
+
You might also add event handler router capabilities into your lambda. This way you might configure different methods in your lambda code to be triggered by different API paths.
132
+
133
+
```python
134
+
from aws_lambda_powertools.event_handler.api_gateway import ApiGatewayResolver
0 commit comments