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
A suite of Python utilities for AWS Lambda functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more. (AWS Lambda Powertools [Java](https://github.com/awslabs/aws-lambda-powertools-java) and [Typescript](https://github.com/awslabs/aws-lambda-powertools-typescript) is also available).
9
+
A suite of Python utilities for AWS Lambda functions to ease adopting best practices such as tracing, structured logging, custom metrics, and more. (AWS Lambda Powertools for [Java](https://github.com/awslabs/aws-lambda-powertools-java), [Typescript](https://github.com/awslabs/aws-lambda-powertools-typescript), and [.NET](https://awslabs.github.io/aws-lambda-powertools-dotnet/){target="_blank"} are also available).
9
10
10
11
**[📜Documentation](https://awslabs.github.io/aws-lambda-powertools-python/)** | **[🐍PyPi](https://pypi.org/project/aws-lambda-powertools/)** | **[Roadmap](https://awslabs.github.io/aws-lambda-powertools-python/latest/roadmap/)** | **[Detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-lambda-powertools/)**
Copy file name to clipboardExpand all lines: docs/core/tracer.md
+8
Original file line number
Diff line number
Diff line change
@@ -19,6 +19,14 @@ Tracer is an opinionated thin wrapper for [AWS X-Ray Python SDK](https://github.
19
19
???+ tip
20
20
All examples shared in this documentation are available within the [project repository](https://github.com/awslabs/aws-lambda-powertools-python/tree/develop/examples){target="_blank"}.
21
21
22
+
### Install
23
+
24
+
!!! info "This is not necessary if you're installing Powertools via [Lambda Layer](../index.md#lambda-layer){target="_blank"}"
25
+
26
+
Add `aws-lambda-powertools[tracer]` as a dependency in your preferred tool: _e.g._, _requirements.txt_, _pyproject.toml_.
27
+
28
+
This will ensure you have the required dependencies before using Tracer.
29
+
22
30
### Permissions
23
31
24
32
Before your use this utility, your AWS Lambda function [must have permissions](https://docs.aws.amazon.com/lambda/latest/dg/services-xray.html#services-xray-permissions) to send traces to AWS X-Ray.
Copy file name to clipboardExpand all lines: docs/index.md
+19-1
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ description: AWS Lambda Powertools for Python
11
11
A suite of utilities for AWS Lambda functions to ease adopting best practices such as tracing, structured logging, custom metrics, idempotency, batching, and more.
12
12
13
13
???+ note
14
-
Lambda Powertools is also available for [Java](https://awslabs.github.io/aws-lambda-powertools-java/){target="_blank"} and [TypeScript](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/){target="_blank"}.
14
+
Powertools is also available for [Java](https://awslabs.github.io/aws-lambda-powertools-java/){target="_blank"}, [TypeScript](https://awslabs.github.io/aws-lambda-powertools-typescript/latest/){target="_blank"}, and [.NET](https://awslabs.github.io/aws-lambda-powertools-dotnet/){target="_blank"}
15
15
16
16
## Install
17
17
@@ -20,11 +20,29 @@ Powertools is available in the following formats:
???+ info "Some utilities require additional dependencies"
24
+
You can stop reading if you're using Lambda Layer.
25
+
26
+
[Tracer](./core/tracer.md){target="_blank"}, [Validation](./utilities/validation.md){target="_blank"} and [Parser](./utilities/parser.md){target="_blank"} require additional dependencies. If you prefer to install all of them, use `pip install aws-lambda-powertools[all]`.
27
+
23
28
???+ hint "Support this project by using Lambda Layers :heart:"
24
29
Lambda Layers allow us to understand who uses this library in a non-intrusive way. This helps us justify and gain future investments for other Lambda Powertools languages.
25
30
26
31
When using Layers, you can add Lambda Powertools as a dev dependency (or as part of your virtual env) to not impact the development process.
27
32
33
+
### Local development
34
+
35
+
Powertools relies on the AWS SDK bundled in the Lambda runtime. This helps us achieve an optimal package size and initialization.
36
+
37
+
This means you need to add AWS SDK as a development dependency (not as a production dependency).
If you're running your code locally with [AWS SAM CLI](https://github.com/aws/aws-sam-cli){target="_blank"}, and not with your Python/IDE interpreter directly, this is not necessary. SAM CLI already brings the AWS SDK in its emulation image.
45
+
28
46
### Lambda Layer
29
47
30
48
[Lambda Layer](https://docs.aws.amazon.com/lambda/latest/dg/configuration-layers.html){target="_blank"} is a .zip file archive that can contain additional code, pre-packaged dependencies, data, or configuration files. Layers promote code sharing and separation of responsibilities so that you can iterate faster on writing business logic.
Install parser's extra dependencies using **`pip install aws-lambda-powertools[pydantic]`**.
27
-
28
-
## Defining models
33
+
### Defining models
29
34
30
35
You can define models to parse incoming events by inheriting from `BaseModel`.
31
36
@@ -47,11 +52,11 @@ class Order(BaseModel):
47
52
48
53
These are simply Python classes that inherit from BaseModel. **Parser** enforces type hints declared in your model at runtime.
49
54
50
-
## Parsing events
55
+
###Parsing events
51
56
52
57
You can parse inbound events using **event_parser** decorator, or the standalone `parse` function. Both are also able to parse either dictionary or JSON string as an input.
53
58
54
-
### event_parser decorator
59
+
####event_parser decorator
55
60
56
61
Use the decorator for fail fast scenarios where you want your Lambda function to raise an exception in the event of a malformed payload.
`root_validator` can help when you have a complex validation mechanism. For example finding whether data has been omitted, comparing field values, etc.
You can read more about validating list items, reusing validators, validating raw inputs, and a lot more in <ahref="https://pydantic-docs.helpmanual.io/usage/validators/">Pydantic's documentation</a>.
472
479
473
-
## Advanced use cases
480
+
###Advanced use cases
474
481
475
482
???+ tip "Tip: Looking to auto-generate models from JSON, YAML, JSON Schemas, OpenApi, etc?"
476
483
Use Koudai Aono's [data model code generation tool for Pydantic](https://github.com/koxudaxi/datamodel-code-generator)
@@ -535,55 +542,3 @@ If what you're trying to use isn't available as part of the high level import sy
535
542
```python title="Pydantic import escape hatch"
536
543
from aws_lambda_powertools.utilities.parser.pydantic import<what you'd like to import'>
537
544
```
538
-
539
-
**What is the cold start impact in bringing this additional dependency?**
540
-
541
-
No significant cold start impact. It does increase the final uncompressed package by **71M**, when you bring the additional dependency that parser requires.
542
-
543
-
Artillery load test sample against a [hello world sample](https://github.com/aws-samples/cookiecutter-aws-sam-python) using Tracer, Metrics, and Logger with and without parser.
Copy file name to clipboardExpand all lines: docs/utilities/validation.md
+8
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,14 @@ This utility provides JSON Schema validation for events and responses, including
18
18
???+ tip
19
19
All examples shared in this documentation are available within the [project repository](https://github.com/awslabs/aws-lambda-powertools-python/tree/develop/examples){target="_blank"}.
20
20
21
+
### Install
22
+
23
+
!!! info "This is not necessary if you're installing Powertools via [Lambda Layer](../index.md#lambda-layer){target="_blank"}"
24
+
25
+
Add `aws-lambda-powertools[validation]` as a dependency in your preferred tool: _e.g._, _requirements.txt_, _pyproject.toml_.
26
+
27
+
This will ensure you have the required dependencies before using Validation.
28
+
21
29
You can validate inbound and outbound events using [`validator` decorator](#validator-decorator).
22
30
23
31
You can also use the standalone `validate` function, if you want more control over the validation process such as handling a validation error.
0 commit comments