Skip to content

feat(typing): add tenant_id property #6985

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 16, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions aws_lambda_powertools/utilities/typing/lambda_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class LambdaContext:
_aws_request_id: str
_log_group_name: str
_log_stream_name: str
_tenant_id: str | None = None
_identity: LambdaCognitoIdentity
_client_context: LambdaClientContext

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

@property
def identity(self) -> LambdaCognitoIdentity:
"""(mobile apps) Information about the Amazon Cognito identity that authorized the request."""
"""Information about the Amazon Cognito identity that authorized the request."""
return self._identity

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

@property
def tenant_id(self) -> str | None:
"""The tenant_id"""
return self._tenant_id

@staticmethod
def get_remaining_time_in_millis() -> int:
"""Returns the number of milliseconds left before the execution times out."""
Expand Down
17 changes: 15 additions & 2 deletions docs/utilities/typing.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,18 @@ Using `LambdaContext` typing makes it possible to access information and hints o
--8<-- "examples/typing/src/working_with_context_function.py"
```

![Utilities Typing All](../media/utilities_typing_2.png)
![Utilities Typing Specific](../media/utilities_typing_3.png)
### Available properties and methods

| Name | Type | Description |
| ------------------------------ | -------- | ------------------------------------------------------------------------- |
| `function_name` | property | The name of the Lambda function |
| `function_version` | property | The version of the function |
| `invoked_function_arn` | property | The Amazon Resource Name (ARN) that's used to invoke the function |
| `memory_limit_in_mb` | property | The amount of memory that's allocated for the function |
| `aws_request_id` | property | The identifier of the invocation request |
| `log_group_name` | property | The log group for the function |
| `log_stream_name` | property | The log stream for the function instance |
| `identity` | property | Information about the Amazon Cognito identity that authorized the request |
| `client_context` | property | Client context that's provided to Lambda by the client application |
| `tenant_id` | property | The tenant_id used to invoke the function |
| `get_remaining_time_in_millis` | method | Returns the number of milliseconds left before the execution times out |
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ def test_typing():
context._aws_request_id = "_aws_request_id"
context._log_group_name = "_log_group_name"
context._log_stream_name = "_log_stream_name"
context._tenant_id = "_tenant_id"
identity = LambdaCognitoIdentity()
identity._cognito_identity_id = "_cognito_identity_id"
identity._cognito_identity_pool_id = "_cognito_identity_pool_id"
Expand All @@ -42,6 +43,7 @@ def test_typing():
assert context.aws_request_id == context._aws_request_id
assert context.log_group_name == context._log_group_name
assert context.log_stream_name == context._log_stream_name
assert context.tenant_id == context._tenant_id
assert context.identity == context._identity
assert context.identity.cognito_identity_id == identity._cognito_identity_id
assert context.identity.cognito_identity_pool_id == identity._cognito_identity_pool_id
Expand Down