aws-lambda-powertools 3.8.1a6__py3-none-any.whl → 3.8.1a8__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aws_lambda_powertools/metrics/provider/datadog/datadog.py +4 -1
- aws_lambda_powertools/shared/version.py +1 -1
- aws_lambda_powertools/utilities/data_classes/__init__.py +2 -0
- aws_lambda_powertools/utilities/data_classes/alb_event.py +2 -6
- aws_lambda_powertools/utilities/data_classes/api_gateway_authorizer_event.py +2 -2
- aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py +12 -21
- aws_lambda_powertools/utilities/data_classes/api_gateway_websocket_event.py +128 -0
- aws_lambda_powertools/utilities/data_classes/appsync_authorizer_event.py +7 -7
- aws_lambda_powertools/utilities/data_classes/bedrock_agent_event.py +2 -4
- aws_lambda_powertools/utilities/data_classes/cognito_user_pool_event.py +116 -169
- aws_lambda_powertools/utilities/data_classes/common.py +46 -47
- aws_lambda_powertools/utilities/data_classes/kinesis_firehose_event.py +7 -11
- aws_lambda_powertools/utilities/data_classes/kinesis_stream_event.py +6 -6
- aws_lambda_powertools/utilities/data_classes/s3_event.py +20 -20
- aws_lambda_powertools/utilities/data_classes/ses_event.py +3 -3
- aws_lambda_powertools/utilities/data_classes/vpc_lattice.py +2 -10
- {aws_lambda_powertools-3.8.1a6.dist-info → aws_lambda_powertools-3.8.1a8.dist-info}/METADATA +2 -2
- {aws_lambda_powertools-3.8.1a6.dist-info → aws_lambda_powertools-3.8.1a8.dist-info}/RECORD +20 -19
- {aws_lambda_powertools-3.8.1a6.dist-info → aws_lambda_powertools-3.8.1a8.dist-info}/LICENSE +0 -0
- {aws_lambda_powertools-3.8.1a6.dist-info → aws_lambda_powertools-3.8.1a8.dist-info}/WHEEL +0 -0
@@ -14,7 +14,7 @@ from aws_lambda_powertools.metrics.functions import is_metrics_disabled
|
|
14
14
|
from aws_lambda_powertools.metrics.provider import BaseProvider
|
15
15
|
from aws_lambda_powertools.metrics.provider.datadog.warnings import DatadogDataValidationWarning
|
16
16
|
from aws_lambda_powertools.shared import constants
|
17
|
-
from aws_lambda_powertools.shared.functions import resolve_env_var_choice
|
17
|
+
from aws_lambda_powertools.shared.functions import resolve_env_var_choice, strtobool
|
18
18
|
|
19
19
|
if TYPE_CHECKING:
|
20
20
|
from aws_lambda_powertools.shared.types import AnyCallableT
|
@@ -66,6 +66,9 @@ class DatadogProvider(BaseProvider):
|
|
66
66
|
)
|
67
67
|
self.default_tags = default_tags or {}
|
68
68
|
self.flush_to_log = resolve_env_var_choice(choice=flush_to_log, env=os.getenv(constants.DATADOG_FLUSH_TO_LOG))
|
69
|
+
# When set as env var, the value is a string
|
70
|
+
if isinstance(self.flush_to_log, str):
|
71
|
+
self.flush_to_log = strtobool(self.flush_to_log)
|
69
72
|
|
70
73
|
# adding name,value,timestamp,tags
|
71
74
|
def add_metric(
|
@@ -4,6 +4,7 @@ Event Source Data Classes utility provides classes self-describing Lambda event
|
|
4
4
|
|
5
5
|
from .alb_event import ALBEvent
|
6
6
|
from .api_gateway_proxy_event import APIGatewayProxyEvent, APIGatewayProxyEventV2
|
7
|
+
from .api_gateway_websocket_event import APIGatewayWebSocketEvent
|
7
8
|
from .appsync_resolver_event import AppSyncResolverEvent
|
8
9
|
from .aws_config_rule_event import AWSConfigRuleEvent
|
9
10
|
from .bedrock_agent_event import BedrockAgentEvent
|
@@ -51,6 +52,7 @@ from .vpc_lattice import VPCLatticeEvent, VPCLatticeEventV2
|
|
51
52
|
__all__ = [
|
52
53
|
"APIGatewayProxyEvent",
|
53
54
|
"APIGatewayProxyEventV2",
|
55
|
+
"APIGatewayWebSocketEvent",
|
54
56
|
"SecretsManagerEvent",
|
55
57
|
"AppSyncResolverEvent",
|
56
58
|
"ALBEvent",
|
@@ -18,7 +18,7 @@ class ALBEventRequestContext(DictWrapper):
|
|
18
18
|
@property
|
19
19
|
def elb_target_group_arn(self) -> str:
|
20
20
|
"""Target group arn for your Lambda function"""
|
21
|
-
return self["
|
21
|
+
return self["elb"]["targetGroupArn"]
|
22
22
|
|
23
23
|
|
24
24
|
class ALBEvent(BaseProxyEvent):
|
@@ -32,11 +32,7 @@ class ALBEvent(BaseProxyEvent):
|
|
32
32
|
|
33
33
|
@property
|
34
34
|
def request_context(self) -> ALBEventRequestContext:
|
35
|
-
return ALBEventRequestContext(self
|
36
|
-
|
37
|
-
@property
|
38
|
-
def multi_value_query_string_parameters(self) -> dict[str, list[str]]:
|
39
|
-
return self.get("multiValueQueryStringParameters") or {}
|
35
|
+
return ALBEventRequestContext(self["requestContext"])
|
40
36
|
|
41
37
|
@property
|
42
38
|
def resolved_query_string_parameters(self) -> dict[str, list[str]]:
|
@@ -183,7 +183,7 @@ class APIGatewayAuthorizerRequestEvent(DictWrapper):
|
|
183
183
|
|
184
184
|
@property
|
185
185
|
def request_context(self) -> BaseRequestContext:
|
186
|
-
return BaseRequestContext(self
|
186
|
+
return BaseRequestContext(self["requestContext"])
|
187
187
|
|
188
188
|
@overload
|
189
189
|
def get_header_value(
|
@@ -306,7 +306,7 @@ class APIGatewayAuthorizerEventV2(DictWrapper):
|
|
306
306
|
|
307
307
|
@property
|
308
308
|
def request_context(self) -> BaseRequestContextV2:
|
309
|
-
return BaseRequestContextV2(self
|
309
|
+
return BaseRequestContextV2(self["requestContext"])
|
310
310
|
|
311
311
|
@property
|
312
312
|
def path_parameters(self) -> dict[str, str]:
|
@@ -61,42 +61,41 @@ class APIGatewayEventRequestContext(BaseRequestContext):
|
|
61
61
|
@property
|
62
62
|
def connected_at(self) -> int | None:
|
63
63
|
"""The Epoch-formatted connection time. (WebSocket API)"""
|
64
|
-
return self
|
64
|
+
return self.get("connectedAt")
|
65
65
|
|
66
66
|
@property
|
67
67
|
def connection_id(self) -> str | None:
|
68
68
|
"""A unique ID for the connection that can be used to make a callback to the client. (WebSocket API)"""
|
69
|
-
return self
|
69
|
+
return self.get("connectionId")
|
70
70
|
|
71
71
|
@property
|
72
72
|
def event_type(self) -> str | None:
|
73
73
|
"""The event type: `CONNECT`, `MESSAGE`, or `DISCONNECT`. (WebSocket API)"""
|
74
|
-
return self
|
74
|
+
return self.get("eventType")
|
75
75
|
|
76
76
|
@property
|
77
77
|
def message_direction(self) -> str | None:
|
78
78
|
"""Message direction (WebSocket API)"""
|
79
|
-
return self
|
79
|
+
return self.get("messageDirection")
|
80
80
|
|
81
81
|
@property
|
82
82
|
def message_id(self) -> str | None:
|
83
83
|
"""A unique server-side ID for a message. Available only when the `eventType` is `MESSAGE`."""
|
84
|
-
return self
|
84
|
+
return self.get("messageId")
|
85
85
|
|
86
86
|
@property
|
87
87
|
def operation_name(self) -> str | None:
|
88
88
|
"""The name of the operation being performed"""
|
89
|
-
return self
|
89
|
+
return self.get("operationName")
|
90
90
|
|
91
91
|
@property
|
92
92
|
def route_key(self) -> str | None:
|
93
93
|
"""The selected route key."""
|
94
|
-
return self
|
94
|
+
return self.get("routeKey")
|
95
95
|
|
96
96
|
@property
|
97
97
|
def authorizer(self) -> APIGatewayEventAuthorizer:
|
98
|
-
|
99
|
-
return APIGatewayEventAuthorizer(authz_data)
|
98
|
+
return APIGatewayEventAuthorizer(self.get("authorizer") or {})
|
100
99
|
|
101
100
|
|
102
101
|
class APIGatewayProxyEvent(BaseProxyEvent):
|
@@ -119,16 +118,9 @@ class APIGatewayProxyEvent(BaseProxyEvent):
|
|
119
118
|
def multi_value_headers(self) -> dict[str, list[str]]:
|
120
119
|
return CaseInsensitiveDict(self.get("multiValueHeaders"))
|
121
120
|
|
122
|
-
@property
|
123
|
-
def multi_value_query_string_parameters(self) -> dict[str, list[str]]:
|
124
|
-
return self.get("multiValueQueryStringParameters") or {} # key might exist but can be `null`
|
125
|
-
|
126
121
|
@property
|
127
122
|
def resolved_query_string_parameters(self) -> dict[str, list[str]]:
|
128
|
-
|
129
|
-
return self.multi_value_query_string_parameters
|
130
|
-
|
131
|
-
return super().resolved_query_string_parameters
|
123
|
+
return self.multi_value_query_string_parameters or super().resolved_query_string_parameters
|
132
124
|
|
133
125
|
@property
|
134
126
|
def resolved_headers_field(self) -> dict[str, Any]:
|
@@ -136,7 +128,7 @@ class APIGatewayProxyEvent(BaseProxyEvent):
|
|
136
128
|
|
137
129
|
@property
|
138
130
|
def request_context(self) -> APIGatewayEventRequestContext:
|
139
|
-
return APIGatewayEventRequestContext(self
|
131
|
+
return APIGatewayEventRequestContext(self["requestContext"])
|
140
132
|
|
141
133
|
@property
|
142
134
|
def path_parameters(self) -> dict[str, str]:
|
@@ -248,8 +240,7 @@ class RequestContextV2Authorizer(DictWrapper):
|
|
248
240
|
class RequestContextV2(BaseRequestContextV2):
|
249
241
|
@property
|
250
242
|
def authorizer(self) -> RequestContextV2Authorizer:
|
251
|
-
|
252
|
-
return RequestContextV2Authorizer(ctx.get("authorizer", {}))
|
243
|
+
return RequestContextV2Authorizer(self.get("authorizer") or {})
|
253
244
|
|
254
245
|
|
255
246
|
class APIGatewayProxyEventV2(BaseProxyEvent):
|
@@ -291,7 +282,7 @@ class APIGatewayProxyEventV2(BaseProxyEvent):
|
|
291
282
|
|
292
283
|
@property
|
293
284
|
def request_context(self) -> RequestContextV2:
|
294
|
-
return RequestContextV2(self
|
285
|
+
return RequestContextV2(self["requestContext"])
|
295
286
|
|
296
287
|
@property
|
297
288
|
def path_parameters(self) -> dict[str, str]:
|
@@ -0,0 +1,128 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
|
3
|
+
import base64
|
4
|
+
from functools import cached_property
|
5
|
+
from typing import Any
|
6
|
+
|
7
|
+
from aws_lambda_powertools.utilities.data_classes.common import (
|
8
|
+
CaseInsensitiveDict,
|
9
|
+
DictWrapper,
|
10
|
+
)
|
11
|
+
|
12
|
+
|
13
|
+
class APIGatewayWebSocketEventIdentity(DictWrapper):
|
14
|
+
@property
|
15
|
+
def source_ip(self) -> str:
|
16
|
+
return self["sourceIp"]
|
17
|
+
|
18
|
+
@property
|
19
|
+
def user_agent(self) -> str | None:
|
20
|
+
return self.get("userAgent")
|
21
|
+
|
22
|
+
|
23
|
+
class APIGatewayWebSocketEventRequestContext(DictWrapper):
|
24
|
+
@property
|
25
|
+
def route_key(self) -> str:
|
26
|
+
return self["routeKey"]
|
27
|
+
|
28
|
+
@property
|
29
|
+
def disconnect_status_code(self) -> int | None:
|
30
|
+
return self.get("disconnectStatusCode")
|
31
|
+
|
32
|
+
@property
|
33
|
+
def message_id(self) -> str | None:
|
34
|
+
return self.get("messageId")
|
35
|
+
|
36
|
+
@property
|
37
|
+
def event_type(self) -> str:
|
38
|
+
return self["eventType"]
|
39
|
+
|
40
|
+
@property
|
41
|
+
def extended_request_id(self) -> str:
|
42
|
+
return self["extendedRequestId"]
|
43
|
+
|
44
|
+
@property
|
45
|
+
def request_time(self) -> str:
|
46
|
+
return self["requestTime"]
|
47
|
+
|
48
|
+
@property
|
49
|
+
def message_direction(self) -> str:
|
50
|
+
return self["messageDirection"]
|
51
|
+
|
52
|
+
@property
|
53
|
+
def disconnect_reason(self) -> str | None:
|
54
|
+
return self.get("disconnectReason")
|
55
|
+
|
56
|
+
@property
|
57
|
+
def stage(self) -> str:
|
58
|
+
return self["stage"]
|
59
|
+
|
60
|
+
@property
|
61
|
+
def connected_at(self) -> int:
|
62
|
+
return self["connectedAt"]
|
63
|
+
|
64
|
+
@property
|
65
|
+
def request_time_epoch(self) -> int:
|
66
|
+
return self["requestTimeEpoch"]
|
67
|
+
|
68
|
+
@property
|
69
|
+
def identity(self) -> APIGatewayWebSocketEventIdentity:
|
70
|
+
return APIGatewayWebSocketEventIdentity(self["identity"])
|
71
|
+
|
72
|
+
@property
|
73
|
+
def request_id(self) -> str:
|
74
|
+
return self["requestId"]
|
75
|
+
|
76
|
+
@property
|
77
|
+
def domain_name(self) -> str:
|
78
|
+
return self["domainName"]
|
79
|
+
|
80
|
+
@property
|
81
|
+
def connection_id(self) -> str:
|
82
|
+
return self["connectionId"]
|
83
|
+
|
84
|
+
@property
|
85
|
+
def api_id(self) -> str:
|
86
|
+
return self["apiId"]
|
87
|
+
|
88
|
+
|
89
|
+
class APIGatewayWebSocketEvent(DictWrapper):
|
90
|
+
"""AWS proxy integration event for WebSocket API
|
91
|
+
|
92
|
+
Documentation:
|
93
|
+
--------------
|
94
|
+
- https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-websocket-api-integration-requests.html
|
95
|
+
"""
|
96
|
+
|
97
|
+
@property
|
98
|
+
def is_base64_encoded(self) -> bool:
|
99
|
+
return self["isBase64Encoded"]
|
100
|
+
|
101
|
+
@property
|
102
|
+
def body(self) -> str | None:
|
103
|
+
return self.get("body")
|
104
|
+
|
105
|
+
@cached_property
|
106
|
+
def decoded_body(self) -> str | None:
|
107
|
+
body = self.body
|
108
|
+
if self.is_base64_encoded and body:
|
109
|
+
return base64.b64decode(body.encode()).decode()
|
110
|
+
return body
|
111
|
+
|
112
|
+
@cached_property
|
113
|
+
def json_body(self) -> Any:
|
114
|
+
if self.decoded_body:
|
115
|
+
return self._json_deserializer(self.decoded_body)
|
116
|
+
return None
|
117
|
+
|
118
|
+
@property
|
119
|
+
def headers(self) -> dict[str, str]:
|
120
|
+
return CaseInsensitiveDict(self.get("headers"))
|
121
|
+
|
122
|
+
@property
|
123
|
+
def multi_value_headers(self) -> dict[str, list[str]]:
|
124
|
+
return CaseInsensitiveDict(self.get("multiValueHeaders"))
|
125
|
+
|
126
|
+
@property
|
127
|
+
def request_context(self) -> APIGatewayWebSocketEventRequestContext:
|
128
|
+
return APIGatewayWebSocketEventRequestContext(self["requestContext"])
|
@@ -11,32 +11,32 @@ class AppSyncAuthorizerEventRequestContext(DictWrapper):
|
|
11
11
|
@property
|
12
12
|
def api_id(self) -> str:
|
13
13
|
"""AppSync API ID"""
|
14
|
-
return self["
|
14
|
+
return self["apiId"]
|
15
15
|
|
16
16
|
@property
|
17
17
|
def account_id(self) -> str:
|
18
18
|
"""AWS Account ID"""
|
19
|
-
return self["
|
19
|
+
return self["accountId"]
|
20
20
|
|
21
21
|
@property
|
22
22
|
def request_id(self) -> str:
|
23
23
|
"""Requestt ID"""
|
24
|
-
return self["
|
24
|
+
return self["requestId"]
|
25
25
|
|
26
26
|
@property
|
27
27
|
def query_string(self) -> str:
|
28
28
|
"""GraphQL query string"""
|
29
|
-
return self["
|
29
|
+
return self["queryString"]
|
30
30
|
|
31
31
|
@property
|
32
32
|
def operation_name(self) -> str | None:
|
33
33
|
"""GraphQL operation name, optional"""
|
34
|
-
return self
|
34
|
+
return self.get("operationName")
|
35
35
|
|
36
36
|
@property
|
37
37
|
def variables(self) -> dict:
|
38
38
|
"""GraphQL variables"""
|
39
|
-
return self["
|
39
|
+
return self["variables"]
|
40
40
|
|
41
41
|
|
42
42
|
class AppSyncAuthorizerEvent(DictWrapper):
|
@@ -57,7 +57,7 @@ class AppSyncAuthorizerEvent(DictWrapper):
|
|
57
57
|
@property
|
58
58
|
def request_context(self) -> AppSyncAuthorizerEventRequestContext:
|
59
59
|
"""Request context"""
|
60
|
-
return AppSyncAuthorizerEventRequestContext(self
|
60
|
+
return AppSyncAuthorizerEventRequestContext(self["requestContext"])
|
61
61
|
|
62
62
|
|
63
63
|
class AppSyncAuthorizerResponse:
|
@@ -57,6 +57,8 @@ class BedrockAgentEvent(BaseProxyEvent):
|
|
57
57
|
See https://docs.aws.amazon.com/bedrock/latest/userguide/agents-create.html
|
58
58
|
"""
|
59
59
|
|
60
|
+
# httpMethod is inherited from BaseProxyEvent class.
|
61
|
+
|
60
62
|
@property
|
61
63
|
def message_version(self) -> str:
|
62
64
|
return self["messageVersion"]
|
@@ -77,10 +79,6 @@ class BedrockAgentEvent(BaseProxyEvent):
|
|
77
79
|
def api_path(self) -> str:
|
78
80
|
return self["apiPath"]
|
79
81
|
|
80
|
-
@property
|
81
|
-
def http_method(self) -> str:
|
82
|
-
return self["httpMethod"]
|
83
|
-
|
84
82
|
@property
|
85
83
|
def parameters(self) -> list[BedrockAgentProperty]:
|
86
84
|
parameters = self.get("parameters") or []
|