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
+4-4
Original file line number
Diff line number
Diff line change
@@ -102,7 +102,7 @@ When using Amazon Application Load Balancer (ALB) to front your Lambda functions
102
102
103
103
#### Lambda Function URL
104
104
105
-
When using [AWS Lambda Function URL](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html), you can use `LambdaFunctionUrlResolver`.
105
+
When using [AWS Lambda Function URL](https://docs.aws.amazon.com/lambda/latest/dg/urls-configuration.html){target="_blank"}, you can use `LambdaFunctionUrlResolver`.
@@ -253,7 +253,7 @@ When using [Custom Domain API Mappings feature](https://docs.aws.amazon.com/apig
253
253
254
254
**Scenario**: You have a custom domain `api.mydomain.dev`. Then you set `/payment` API Mapping to forward any payment requests to your Payments API.
255
255
256
-
**Challenge**: This means your `path` value for any API requests will always contain `/payment/<actual_request>`, leading to HTTP 404 as Event Handler is trying to match what's after `payment/`. This gets further complicated with an [arbitrary level of nesting](https://github.com/awslabs/aws-lambda-powertools-roadmap/issues/34).
256
+
**Challenge**: This means your `path` value for any API requests will always contain `/payment/<actual_request>`, leading to HTTP 404 as Event Handler is trying to match what's after `payment/`. This gets further complicated with an [arbitrary level of nesting](https://github.com/awslabs/aws-lambda-powertools-roadmap/issues/34){target="_blank"}.
257
257
258
258
To address this API Gateway behavior, we use `strip_prefixes` parameter to account for these prefixes that are now injected into the path regardless of which type of API Gateway you're using.
259
259
@@ -344,7 +344,7 @@ You can use the `Response` class to have full control over the response. For exa
344
344
Some event sources require headers and cookies to be encoded as `multiValueHeaders`.
345
345
346
346
???+ warning "Using multiple values for HTTP headers in ALB?"
347
-
Make sure you [enable the multi value headers feature](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers) to serialize response headers correctly.
347
+
Make sure you [enable the multi value headers feature](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/lambda-functions.html#multi-value-headers){target="_blank"} to serialize response headers correctly.
348
348
349
349
=== "fine_grained_responses.py"
350
350
@@ -420,7 +420,7 @@ Like `compress` feature, the client must send the `Accept` header with the corre
420
420
421
421
### Debug mode
422
422
423
-
You can enable debug mode via `debug` param, or via `POWERTOOLS_DEV`[environment variable](../../index.md#environment-variables).
423
+
You can enable debug mode via `debug` param, or via `POWERTOOLS_DEV`[environment variable](../../index.md#environment-variables){target="_blank"}.
424
424
425
425
This will enable full tracebacks errors in the response, print request and responses, and set CORS in development mode.
Copy file name to clipboardExpand all lines: docs/core/logger.md
+5-5
Original file line number
Diff line number
Diff line change
@@ -108,7 +108,7 @@ You can set a Correlation ID using `correlation_id_path` param by passing a [JME
108
108
109
109
#### set_correlation_id method
110
110
111
-
You can also use `set_correlation_id` method to inject it anywhere else in your code. Example below uses [Event Source Data Classes utility](../utilities/data_classes.md) to easily access events properties.
111
+
You can also use `set_correlation_id` method to inject it anywhere else in your code. Example below uses [Event Source Data Classes utility](../utilities/data_classes.md){target="_blank"} to easily access events properties.
112
112
113
113
=== "set_correlation_id_method.py"
114
114
@@ -242,7 +242,7 @@ You can remove any additional key from Logger state using `remove_keys`.
242
242
243
243
#### Clearing all state
244
244
245
-
Logger is commonly initialized in the global scope. Due to [Lambda Execution Context reuse](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html), this means that custom keys can be persisted across invocations. If you want all custom keys to be deleted, you can use `clear_state=True` param in `inject_lambda_context` decorator.
245
+
Logger is commonly initialized in the global scope. Due to [Lambda Execution Context reuse](https://docs.aws.amazon.com/lambda/latest/dg/runtimes-context.html){target="_blank"}, this means that custom keys can be persisted across invocations. If you want all custom keys to be deleted, you can use `clear_state=True` param in `inject_lambda_context` decorator.
246
246
247
247
???+ tip "Tip: When is this useful?"
248
248
It is useful when you add multiple custom keys conditionally, instead of setting a default `None` value if not present. Any key with `None` value is automatically removed by Logger.
@@ -360,7 +360,7 @@ You can use any of the following built-in JMESPath expressions as part of [injec
360
360
361
361
### Reusing Logger across your code
362
362
363
-
Similar to [Tracer](./tracer.md#reusing-tracer-across-your-code), a new instance that uses the same `service` name - env var or explicit parameter - will reuse a previous Logger instance. Just like `logging.getLogger("logger_name")` would in the standard library if called with the same logger name.
363
+
Similar to [Tracer](./tracer.md#reusing-tracer-across-your-code){target="_blank"}, a new instance that uses the same `service` name - env var or explicit parameter - will reuse a previous Logger instance. Just like `logging.getLogger("logger_name")` would in the standard library if called with the same logger name.
364
364
365
365
Notice in the CloudWatch Logs output how `payment_id` appeared as expected when logging in `collect.py`.
366
366
@@ -407,7 +407,7 @@ You can use values ranging from `0.0` to `1` (100%) when setting `POWERTOOLS_LOG
407
407
Sampling decision happens at the Logger initialization. This means sampling may happen significantly more or less than depending on your traffic patterns, for example a steady low number of invocations and thus few cold starts.
408
408
409
409
???+ note
410
-
Open a [feature request](https://github.com/awslabs/aws-lambda-powertools-python/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=) if you want Logger to calculate sampling for every invocation
410
+
Open a [feature request](https://github.com/awslabs/aws-lambda-powertools-python/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=){target="_blank"} if you want Logger to calculate sampling for every invocation
411
411
412
412
=== "sampling_debug_logs.py"
413
413
@@ -744,4 +744,4 @@ Here's an example where we persist `payment_id` not `request_id`. Note that `pay
744
744
<!-- markdownlint-disable MD013 -->
745
745
### How do I aggregate and search Powertools for AWS Lambda (Python) logs across accounts?
746
746
747
-
As of now, ElasticSearch (ELK) or 3rd party solutions are best suited to this task. Please refer to this [discussion for more details](https://github.com/awslabs/aws-lambda-powertools-python/issues/460)
747
+
As of now, ElasticSearch (ELK) or 3rd party solutions are best suited to this task. Please refer to this [discussion for more details](https://github.com/awslabs/aws-lambda-powertools-python/issues/460){target="_blank"}
Copy file name to clipboardExpand all lines: docs/core/metrics.md
+10-10
Original file line number
Diff line number
Diff line change
@@ -3,9 +3,9 @@ title: Metrics
3
3
description: Core utility
4
4
---
5
5
6
-
Metrics creates custom metrics asynchronously by logging metrics to standard output following [Amazon CloudWatch Embedded Metric Format (EMF)](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html).
6
+
Metrics creates custom metrics asynchronously by logging metrics to standard output following [Amazon CloudWatch Embedded Metric Format (EMF)](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/CloudWatch_Embedded_Metric_Format.html){target="_blank"}.
7
7
8
-
These metrics can be visualized through [Amazon CloudWatch Console](https://console.aws.amazon.com/cloudwatch/).
8
+
These metrics can be visualized through [Amazon CloudWatch Console](https://console.aws.amazon.com/cloudwatch/){target="_blank"}.
9
9
10
10
## Key features
11
11
@@ -22,7 +22,7 @@ If you're new to Amazon CloudWatch, there are two terminologies you must be awar
22
22
***Dimensions**. Metrics metadata in key-value format. They help you slice and dice metrics visualization, for example `ColdStart` metric by Payment `service`.
23
23
***Metric**. It's the name of the metric, for example: `SuccessfulBooking` or `UpdatedBooking`.
24
24
***Unit**. It's a value representing the unit of measure for the corresponding metric, for example: `Count` or `Seconds`.
25
-
***Resolution**. It's a value representing the storage resolution for the corresponding metric. Metrics can be either Standard or High resolution. Read more [here](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#high-resolution-metrics).
25
+
***Resolution**. It's a value representing the storage resolution for the corresponding metric. Metrics can be either Standard or High resolution. Read more [here](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/publishingMetrics.html#high-resolution-metrics){target="_blank"}.
26
26
27
27
<figure>
28
28
<imgsrc="../../media/metrics_terminology.png" />
@@ -83,7 +83,7 @@ You can create metrics using `add_metric`, and you can create dimensions for all
83
83
84
84
### Adding high-resolution metrics
85
85
86
-
You can create [high-resolution metrics](https://aws.amazon.com/about-aws/whats-new/2023/02/amazon-cloudwatch-high-resolution-metric-extraction-structured-logs/) passing `resolution` parameter to `add_metric`.
86
+
You can create [high-resolution metrics](https://aws.amazon.com/about-aws/whats-new/2023/02/amazon-cloudwatch-high-resolution-metric-extraction-structured-logs/){target="_blank"} passing `resolution` parameter to `add_metric`.
87
87
88
88
???+ tip "When is it useful?"
89
89
High-resolution metrics are data with a granularity of one second and are very useful in several situations such as telemetry, time series, real-time incident management, and others.
@@ -154,7 +154,7 @@ This decorator also **validates**, **serializes**, and **flushes** all your metr
154
154
155
155
* Maximum of 29 user-defined dimensions
156
156
* Namespace is set, and no more than one
157
-
* Metric units must be [supported by CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html)
157
+
* Metric units must be [supported by CloudWatch](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html){target="_blank"}
158
158
159
159
#### Raising SchemaValidationError on empty metrics
160
160
@@ -191,7 +191,7 @@ If it's a cold start invocation, this feature will:
191
191
This has the advantage of keeping cold start metric separate from your application metrics, where you might have unrelated dimensions.
192
192
193
193
???+ info
194
-
We do not emit 0 as a value for ColdStart metric for cost reasons. [Let us know](https://github.com/awslabs/aws-lambda-powertools-python/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=) if you'd prefer a flag to override it.
194
+
We do not emit 0 as a value for ColdStart metric for cost reasons. [Let us know](https://github.com/awslabs/aws-lambda-powertools-python/issues/new?assignees=&labels=feature-request%2C+triage&template=feature_request.md&title=){target="_blank"} if you'd prefer a flag to override it.
195
195
196
196
## Advanced
197
197
@@ -219,7 +219,7 @@ You can add high-cardinality data as part of your Metrics log with `add_metadata
219
219
CloudWatch EMF uses the same dimensions across all your metrics. Use `single_metric` if you have a metric that should have different dimensions.
220
220
221
221
???+ info
222
-
Generally, this would be an edge case since you [pay for unique metric](https://aws.amazon.com/cloudwatch/pricing). Keep the following formula in mind:
222
+
Generally, this would be an edge case since you [pay for unique metric](https://aws.amazon.com/cloudwatch/pricing){target="_blank"}. Keep the following formula in mind:
@@ -292,7 +292,7 @@ The former creates metrics asynchronously via CloudWatch Logs, and the latter us
292
292
!!! important "Key concept"
293
293
CloudWatch [considers a metric unique](https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch_concepts.html#Metric){target="_blank"} by a combination of metric **name**, metric **namespace**, and zero or more metric **dimensions**.
294
294
295
-
With EMF, metric dimensions are shared with any metrics you define. With `PutMetricData` API, you can set a [list](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html) defining one or more metrics with distinct dimensions.
295
+
With EMF, metric dimensions are shared with any metrics you define. With `PutMetricData` API, you can set a [list](https://docs.aws.amazon.com/AmazonCloudWatch/latest/APIReference/API_MetricDatum.html){target="_blank"} defining one or more metrics with distinct dimensions.
296
296
297
297
This is a subtle yet important distinction. Imagine you had the following metrics to emit:
298
298
@@ -329,7 +329,7 @@ That is why `Metrics` shares data across instances by default, as that covers 80
329
329
330
330
For example, `Metrics(namespace="ServerlessAirline", service="booking")`
331
331
332
-
Make sure to set `POWERTOOLS_METRICS_NAMESPACE` and `POWERTOOLS_SERVICE_NAME` before running your tests to prevent failing on `SchemaValidation` exception. You can set it before you run tests or via pytest plugins like [dotenv](https://pypi.org/project/pytest-dotenv/).
332
+
Make sure to set `POWERTOOLS_METRICS_NAMESPACE` and `POWERTOOLS_SERVICE_NAME` before running your tests to prevent failing on `SchemaValidation` exception. You can set it before you run tests or via pytest plugins like [dotenv](https://pypi.org/project/pytest-dotenv/){target="_blank"}.
333
333
334
334
```bash title="Injecting dummy Metric Namespace before running tests"
@@ -374,4 +374,4 @@ You can read standard output and assert whether metrics have been flushed. Here'
374
374
```
375
375
376
376
???+ tip
377
-
For more elaborate assertions and comparisons, check out [our functional testing for Metrics utility.](https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/tests/functional/test_metrics.py)
377
+
For more elaborate assertions and comparisons, check out [our functional testing for Metrics utility.](https://github.com/awslabs/aws-lambda-powertools-python/blob/develop/tests/functional/test_metrics.py){target="_blank"}
@@ -29,7 +29,7 @@ Add `aws-lambda-powertools[tracer]` as a dependency in your preferred tool: _e.g
29
29
30
30
### Permissions
31
31
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.
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){target="_blank"} to send traces to AWS X-Ray.
33
33
34
34
```yaml hl_lines="9 12" title="AWS Serverless Application Model (SAM) example"
35
35
--8<-- "examples/tracer/sam/template.yaml"
@@ -51,7 +51,7 @@ You can quickly start by initializing `Tracer` and use `capture_lambda_handler`
51
51
52
52
### Annotations & Metadata
53
53
54
-
**Annotations** are key-values associated with traces and indexed by AWS X-Ray. You can use them to filter traces and to create [Trace Groups](https://aws.amazon.com/about-aws/whats-new/2018/11/aws-xray-adds-the-ability-to-group-traces/) to slice and dice your transactions.
54
+
**Annotations** are key-values associated with traces and indexed by AWS X-Ray. You can use them to filter traces and to create [Trace Groups](https://aws.amazon.com/about-aws/whats-new/2018/11/aws-xray-adds-the-ability-to-group-traces/){target="_blank"} to slice and dice your transactions.
55
55
56
56
```python hl_lines="8" title="Adding annotations with put_annotation method"
@@ -107,7 +107,7 @@ You can trace asynchronous functions and generator functions (including context
107
107
108
108
### Patching modules
109
109
110
-
Tracer automatically patches all [supported libraries by X-Ray](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-python-patching.html) during initialization, by default. Underneath, AWS X-Ray SDK checks whether a supported library has been imported before patching.
110
+
Tracer automatically patches all [supported libraries by X-Ray](https://docs.aws.amazon.com/xray/latest/devguide/xray-sdk-python-patching.html){target="_blank"} during initialization, by default. Underneath, AWS X-Ray SDK checks whether a supported library has been imported before patching.
111
111
112
112
If you're looking to shave a few microseconds, or milliseconds depending on your function memory configuration, you can patch specific modules using `patch_modules` param:
113
113
@@ -172,7 +172,7 @@ You can use `aiohttp_trace_config` function to create a valid [aiohttp trace_con
172
172
173
173
You can use `tracer.provider` attribute to access all methods provided by AWS X-Ray `xray_recorder` object.
174
174
175
-
This is useful when you need a feature available in X-Ray that is not available in the Tracer utility, for example [thread-safe](https://github.com/aws/aws-xray-sdk-python/#user-content-trace-threadpoolexecutor), or [context managers](https://github.com/aws/aws-xray-sdk-python/#user-content-start-a-custom-segmentsubsegment).
175
+
This is useful when you need a feature available in X-Ray that is not available in the Tracer utility, for example [thread-safe](https://github.com/aws/aws-xray-sdk-python/#user-content-trace-threadpoolexecutor){target="_blank"}, or [context managers](https://github.com/aws/aws-xray-sdk-python/#user-content-start-a-custom-segmentsubsegment){target="_blank"}.
176
176
177
177
```python hl_lines="14" title="Tracing a code block with in_subsegment escape hatch"
178
178
--8<--"examples/tracer/src/sdk_escape_hatch.py"
@@ -181,7 +181,7 @@ This is useful when you need a feature available in X-Ray that is not available
181
181
### Concurrent asynchronous functions
182
182
183
183
???+ warning
184
-
[X-Ray SDK will raise an exception](https://github.com/aws/aws-xray-sdk-python/issues/164) when async functions are run and traced concurrently
184
+
[X-Ray SDK will raise an exception](https://github.com/aws/aws-xray-sdk-python/issues/164){target="_blank"} when async functions are run and traced concurrently
185
185
186
186
A safe workaround mechanism is to use `in_subsegment_async` available via Tracer escape hatch (`tracer.provider`).
187
187
@@ -221,4 +221,4 @@ Tracer is disabled by default when not running in the AWS Lambda environment - T
221
221
222
222
* Use annotations on key operations to slice and dice traces, create unique views, and create metrics from it via Trace Groups
223
223
* Use a namespace when adding metadata to group data more easily
224
-
* Annotations and metadata are added to the current subsegment opened. If you want them in a specific subsegment, use a [context manager](https://github.com/aws/aws-xray-sdk-python/#start-a-custom-segmentsubsegment) via the escape hatch mechanism
224
+
* Annotations and metadata are added to the current subsegment opened. If you want them in a specific subsegment, use a [context manager](https://github.com/aws/aws-xray-sdk-python/#start-a-custom-segmentsubsegment){target="_blank"} via the escape hatch mechanism
0 commit comments