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: docs/core/event_handler/api_gateway.md
+24-20
Original file line number
Diff line number
Diff line change
@@ -18,10 +18,12 @@ Event handler for Amazon API Gateway REST and HTTP APIs, and Application Loader
18
18
19
19
### Required resources
20
20
21
-
You must have an existing [API Gateway Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html){target="_blank"} or [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html){target="_blank"} configured to invoke your Lambda function. There is no additional permissions or dependencies required to use this utility.
21
+
You must have an existing [API Gateway Proxy integration](https://docs.aws.amazon.com/apigateway/latest/developerguide/set-up-lambda-proxy-integrations.html){target="_blank"} or [ALB](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html){target="_blank"} configured to invoke your Lambda function.
22
22
23
23
This is the sample infrastructure for API Gateway we are using for the examples in this documentation.
24
24
25
+
???+ info "There is no additional permissions or dependencies required to use this utility."
26
+
25
27
```yaml title="AWS Serverless Application Model (SAM) example"
You can use **`exception_handler`** decorator with any Python exception. This allows you to handle a common exception outside your route, for example validation errors.
@@ -754,13 +759,13 @@ For convenience, these are the default values when using `CORSConfig` to enable
754
759
???+ warning
755
760
Always configure `allow_origin` when using in production.
**[allow_origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin){target="_blank"}**: `str` | `*` | Only use the default value for development. **Never use `*` for production** unless your use case requires it
760
-
**[allow_headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers){target="_blank"}**: `List[str]` | `[Authorization, Content-Type, X-Amz-Date, X-Api-Key, X-Amz-Security-Token]` | Additional headers will be appended to the default list for your convenience
761
-
**[expose_headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers){target="_blank"}**: `List[str]` | `[]` | Any additional header beyond the [safe listed by CORS specification](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header){target="_blank"}.
762
-
**[max_age](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age){target="_blank"}**: `int` | `` | Only for pre-flight requests if you choose to have your function to handle it instead of API Gateway
763
-
**[allow_credentials](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials){target="_blank"}**: `bool` | `False` | Only necessary when you need to expose cookies, authorization headers or TLS client certificates.
|**[allow_origin](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Origin){target="_blank"}**: `str`|`*`| Only use the default value for development. **Never use `*` for production** unless your use case requires it|
765
+
|**[allow_headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Headers){target="_blank"}**: `List[str]`|`[Authorization, Content-Type, X-Amz-Date, X-Api-Key, X-Amz-Security-Token]`| Additional headers will be appended to the default list for your convenience|
766
+
|**[expose_headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Expose-Headers){target="_blank"}**: `List[str]`|`[]`| Any additional header beyond the [safe listed by CORS specification](https://developer.mozilla.org/en-US/docs/Glossary/CORS-safelisted_response_header){target="_blank"}.|
767
+
|**[max_age](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Max-Age){target="_blank"}**: `int`| `` | Only for pre-flight requests if you choose to have your function to handle it instead of API Gateway|
768
+
|**[allow_credentials](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Access-Control-Allow-Credentials){target="_blank"}**: `bool`|`False`| Only necessary when you need to expose cookies, authorization headers or TLS client certificates.|
764
769
765
770
### Fine grained responses
766
771
@@ -1132,7 +1137,6 @@ This sample project contains a Users function with two distinct set of routes, `
1132
1137
1133
1138
=== "Project layout"
1134
1139
1135
-
1136
1140
```python hl_lines="1 8 10 12-15"
1137
1141
.
1138
1142
├── Pipfile # project app & dev dependencies; poetry, pipenv, etc.
@@ -1308,7 +1312,7 @@ _**Downsides**_
1308
1312
1309
1313
***Cold starts**. Frequent deployments and/or high load can diminish the benefit of monolithic functions depending on your latency requirements, due to [Lambda scaling model](https://docs.aws.amazon.com/lambda/latest/dg/invocation-scaling.html){target="_blank"}. Always load test to pragmatically balance between your customer experience and development cognitive load.
1310
1314
***Granular security permissions**. The micro function approach enables you to use fine-grained permissions & access controls, separate external dependencies & code signing at the function level. Conversely, you could have multiple functions while duplicating the final code artifact in a monolithic approach.
1311
-
- Regardless, least privilege can be applied to either approaches.
1315
+
* Regardless, least privilege can be applied to either approaches.
1312
1316
***Higher risk per deployment**. A misconfiguration or invalid import can cause disruption if not caught earlier in automated testing. Multiple functions can mitigate misconfigurations but they would still share the same code artifact. You can further minimize risks with multiple environments in your CI/CD pipeline.
1313
1317
1314
1318
#### Micro function
@@ -1317,20 +1321,20 @@ _**Downsides**_
1317
1321
1318
1322
A micro function means that your final code artifact will be different to each function deployed. This is generally the approach to start if you're looking for fine-grain control and/or high load on certain parts of your service.
1319
1323
1320
-
_**Benefits**_
1324
+
**Benefits**
1321
1325
1322
1326
***Granular scaling**. A micro function can benefit from the [Lambda scaling model](https://docs.aws.amazon.com/lambda/latest/dg/invocation-scaling.html){target="_blank"} to scale differently depending on each part of your application. Concurrency controls and provisioned concurrency can also be used at a granular level for capacity management.
1323
1327
***Discoverability**. Micro functions are easier do visualize when using distributed tracing. Their high-level architectures can be self-explanatory, and complexity is highly visible — assuming each function is named to the business purpose it serves.
1324
1328
***Package size**. An independent function can be significant smaller (KB vs MB) depending on external dependencies it require to perform its purpose. Conversely, a monolithic approach can benefit from [Lambda Layers](https://docs.aws.amazon.com/lambda/latest/dg/invocation-layers.html){target="_blank"} to optimize builds for external dependencies.
1325
1329
1326
-
_**Downsides**_
1330
+
**Downsides**
1327
1331
1328
-
***Upfront investment**. Python ecosystem doesn't use a bundler — you need a custom build tooling to ensure each function only has what it needs and account for [C bindings for runtime compatibility](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html){target="_blank"}. Operations become more elaborate — you need to standardize tracing labels/annotations, structured logging, and metrics to pinpoint root causes.
1329
-
- Engineering discipline is necessary for both approaches. Micro-function approach however requires further attention in consistency as the number of functions grow, just like any distributed system.
1332
+
***Upfront investment**. You need custom build tooling to bundle assets, including [C bindings for runtime compatibility](https://docs.aws.amazon.com/lambda/latest/dg/lambda-runtimes.html){target="_blank"}. `Operations become more elaborate — you need to standardize tracing labels/annotations, structured logging, and metrics to pinpoint root causes.
1333
+
* Engineering discipline is necessary for both approaches. Micro-function approach however requires further attention in consistency as the number of functions grow, just like any distributed system.
1330
1334
***Harder to share code**. Shared code must be carefully evaluated to avoid unnecessary deployments when that changes. Equally, if shared code isn't a library,
1331
1335
your development, building, deployment tooling need to accommodate the distinct layout.
1332
1336
***Slower safe deployments**. Safely deploying multiple functions require coordination — AWS CodeDeploy deploys and verifies each function sequentially. This increases lead time substantially (minutes to hours) depending on the deployment strategy you choose. You can mitigate it by selectively enabling it in prod-like environments only, and where the risk profile is applicable.
1333
-
- Automated testing, operational and security reviews are essential to stability in either approaches.
1337
+
* Automated testing, operational and security reviews are essential to stability in either approaches.
Copy file name to clipboardExpand all lines: docs/core/logger.md
-3
Original file line number
Diff line number
Diff line change
@@ -736,7 +736,6 @@ You might want to continue to use the same date formatting style, or override `l
736
736
737
737
Logger allows you to either change the format or suppress the following keys altogether at the initialization: `location`, `timestamp`, `level`, `xray_trace_id`.
738
738
739
-
740
739
=== "lambda_handler.py"
741
740
```python hl_lines="7 10"
742
741
from aws_lambda_powertools import Logger
@@ -902,7 +901,6 @@ For exceptional cases where you want to completely replace our formatter logic,
902
901
???+ warning
903
902
You will need to implement `append_keys`, `clear_state`, override `format`, and optionally `remove_keys` to keep the same feature set Powertools Logger provides. This also means keeping state of logging keys added.
You can copy the Logger setup to all or sub-sets of registered external loggers. Use the `copy_config_to_registered_logger` method to do this. By default all registered loggers will be modified. You can change this behaviour by providing `include` and `exclude` attributes. You can also provide optional `log_level` attribute external loggers will be configured with.
1086
1084
1087
-
1088
1085
```python hl_lines="10" title="Cloning Logger config to all other registered standard loggers"
The serialization is performed by aws-xray-sdk via `jsonpickle` module. This can cause
102
102
side effects for file-like objects like boto S3 <a href="https://botocore.amazonaws.com/v1/documentation/api/latest/reference/response.html#botocore.response.StreamingBody">`StreamingBody`</a>, where its response will be read only once during serialization.
Copy file name to clipboardExpand all lines: docs/index.md
+1-5
Original file line number
Diff line number
Diff line change
@@ -9,7 +9,6 @@ A suite of utilities for AWS Lambda functions to ease adopting best practices su
9
9
10
10
Check out [this detailed blog post](https://aws.amazon.com/blogs/opensource/simplifying-serverless-best-practices-with-lambda-powertools/) with a practical example.
11
11
12
-
13
12
## Install
14
13
15
14
Powertools is available in the following formats:
@@ -22,7 +21,6 @@ Powertools is available in the following formats:
22
21
23
22
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.
24
23
25
-
26
24
### Lambda Layer
27
25
28
26
[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.
@@ -187,7 +185,6 @@ You can include Lambda Powertools Lambda Layer using [AWS Lambda Console](https:
187
185
188
186
Lambda Powertools Lambda Layer do not include `pydantic` library - required dependency for the `parser` utility. See [SAR](#sar) option instead.
189
187
190
-
191
188
#### SAR
192
189
193
190
Serverless Application Repository (SAR) App deploys a CloudFormation stack with a copy of our Lambda Layer in your AWS account and region.
@@ -205,7 +202,6 @@ Despite having more steps compared to the [public Layer ARN](#lambda-layer) opti
205
202
???+ tip
206
203
You can create a shared Lambda Layers stack and make this along with other account level layers stack.
207
204
208
-
209
205
If using SAM, you can include this SAR App as part of your shared Layers stack, and lock to a specific semantic version. Once deployed, it'll be available across the account this is deployed to.
210
206
211
207
=== "SAM"
@@ -460,7 +456,7 @@ from aws_lambda_powertools.logging.logger import set_package_logger
460
456
set_package_logger() # (1)
461
457
```
462
458
463
-
1.:information_source: this will configure our `aws_lambda_powertools` logger with debug.
459
+
1.:information_source: this will configure our `aws_lambda_powertools` logger with debug.
0 commit comments