Skip to content

Commit 5276b9c

Browse files
feat(typing): add tenant_id property (#6985)
* Adding tenant_id property * Improve documentation
1 parent 6d0b8b9 commit 5276b9c

File tree

3 files changed

+25
-4
lines changed

3 files changed

+25
-4
lines changed

aws_lambda_powertools/utilities/typing/lambda_context.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class LambdaContext:
3434
_aws_request_id: str
3535
_log_group_name: str
3636
_log_stream_name: str
37+
_tenant_id: str | None = None
3738
_identity: LambdaCognitoIdentity
3839
_client_context: LambdaClientContext
3940

@@ -75,14 +76,19 @@ def log_stream_name(self) -> str:
7576

7677
@property
7778
def identity(self) -> LambdaCognitoIdentity:
78-
"""(mobile apps) Information about the Amazon Cognito identity that authorized the request."""
79+
"""Information about the Amazon Cognito identity that authorized the request."""
7980
return self._identity
8081

8182
@property
8283
def client_context(self) -> LambdaClientContext:
83-
"""(mobile apps) Client context that's provided to Lambda by the client application."""
84+
"""Client context that's provided to Lambda by the client application."""
8485
return self._client_context
8586

87+
@property
88+
def tenant_id(self) -> str | None:
89+
"""The tenant_id"""
90+
return self._tenant_id
91+
8692
@staticmethod
8793
def get_remaining_time_in_millis() -> int:
8894
"""Returns the number of milliseconds left before the execution times out."""

docs/utilities/typing.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,5 +42,18 @@ Using `LambdaContext` typing makes it possible to access information and hints o
4242
--8<-- "examples/typing/src/working_with_context_function.py"
4343
```
4444

45-
![Utilities Typing All](../media/utilities_typing_2.png)
46-
![Utilities Typing Specific](../media/utilities_typing_3.png)
45+
### Available properties and methods
46+
47+
| Name | Type | Description |
48+
| ------------------------------ | -------- | ------------------------------------------------------------------------- |
49+
| `function_name` | property | The name of the Lambda function |
50+
| `function_version` | property | The version of the function |
51+
| `invoked_function_arn` | property | The Amazon Resource Name (ARN) that's used to invoke the function |
52+
| `memory_limit_in_mb` | property | The amount of memory that's allocated for the function |
53+
| `aws_request_id` | property | The identifier of the invocation request |
54+
| `log_group_name` | property | The log group for the function |
55+
| `log_stream_name` | property | The log stream for the function instance |
56+
| `identity` | property | Information about the Amazon Cognito identity that authorized the request |
57+
| `client_context` | property | Client context that's provided to Lambda by the client application |
58+
| `tenant_id` | property | The tenant_id used to invoke the function |
59+
| `get_remaining_time_in_millis` | method | Returns the number of milliseconds left before the execution times out |

tests/functional/typing/required_dependencies/test_utilities_typing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ def test_typing():
1919
context._aws_request_id = "_aws_request_id"
2020
context._log_group_name = "_log_group_name"
2121
context._log_stream_name = "_log_stream_name"
22+
context._tenant_id = "_tenant_id"
2223
identity = LambdaCognitoIdentity()
2324
identity._cognito_identity_id = "_cognito_identity_id"
2425
identity._cognito_identity_pool_id = "_cognito_identity_pool_id"
@@ -42,6 +43,7 @@ def test_typing():
4243
assert context.aws_request_id == context._aws_request_id
4344
assert context.log_group_name == context._log_group_name
4445
assert context.log_stream_name == context._log_stream_name
46+
assert context.tenant_id == context._tenant_id
4547
assert context.identity == context._identity
4648
assert context.identity.cognito_identity_id == identity._cognito_identity_id
4749
assert context.identity.cognito_identity_pool_id == identity._cognito_identity_pool_id

0 commit comments

Comments
 (0)