Skip to content

Commit 9f5dee0

Browse files
Addressing Heitor's feedback
1 parent bb226af commit 9f5dee0

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

aws_lambda_powertools/utilities/data_classes/api_gateway_proxy_event.py

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,24 @@ def integration_latency(self) -> Optional[int]:
3333
"""The authorizer latency in ms."""
3434
return self.get("integrationLatency")
3535

36-
def get_context(self) -> Optional[Dict[str, Any]]:
37-
"""Retrieve the authorization context details for Lambda.
36+
def get_context(self) -> Dict[str, Any]:
37+
"""Retrieve the authorization context details injected by a Lambda Authorizer.
38+
39+
Example
40+
--------
41+
42+
```python
43+
ctx: dict = ...request_context.authorizer.get_context()
44+
45+
tenant_id = ctx.get("tenant_id")
46+
```
3847
3948
Returns:
4049
--------
41-
Optional[Dict[str, Any]]
42-
A dictionary containing Lambda authorization context details, or None if the information is not available.
50+
Dict[str, Any]
51+
A dictionary containing Lambda authorization context details.
4352
"""
44-
return self
53+
return self._data
4554

4655

4756
class APIGatewayEventRequestContext(BaseRequestContext):
@@ -195,14 +204,23 @@ def get_lambda(self) -> Optional[Dict[str, Any]]:
195204
return self.get("lambda")
196205

197206
def get_context(self) -> Optional[Dict[str, Any]]:
198-
"""Retrieve the authorization context details for Lambda.
207+
"""Retrieve the authorization context details injected by a Lambda Authorizer.
208+
209+
Example
210+
--------
211+
212+
```python
213+
ctx: dict = ...request_context.authorizer.get_context()
214+
215+
tenant_id = ctx.get("tenant_id")
216+
```
199217
200218
Returns:
201219
--------
202-
Optional[Dict[str, Any]]
203-
A dictionary containing Lambda authorization context details, or None if the information is not available.
220+
Dict[str, Any]
221+
A dictionary containing Lambda authorization context details.
204222
"""
205-
return self.get("lambda")
223+
return self.get("lambda", {})
206224

207225
@property
208226
def iam(self) -> Optional[RequestContextV2AuthorizerIam]:

0 commit comments

Comments
 (0)