|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +from aws_lambda_powertools.utilities.typing.lambda_client_context import LambdaClientContext |
| 3 | +from aws_lambda_powertools.utilities.typing.lambda_cognito_identity import LambdaCognitoIdentity |
| 4 | + |
| 5 | + |
| 6 | +class LambdaContext(object): |
| 7 | + """The LambdaContext static object can be used to ease the development by providing the IDE type hints. |
| 8 | +
|
| 9 | + Example |
| 10 | + ------- |
| 11 | + **A Lambda function using LambdaContext** |
| 12 | +
|
| 13 | + >>> from aws_lambda_powertools.utilities.typing import LambdaContext |
| 14 | + >>> |
| 15 | + >>> def handler(event: Dict[str, Any], context: LambdaContext) -> Dict[str, Any]: |
| 16 | + >>> # Insert business logic |
| 17 | + >>> return event |
| 18 | +
|
| 19 | + """ |
| 20 | + |
| 21 | + _function_name: str |
| 22 | + _function_version: str |
| 23 | + _invoked_function_arn: str |
| 24 | + _memory_limit_in_mb: int |
| 25 | + _aws_request_id: str |
| 26 | + _log_group_name: str |
| 27 | + _log_stream_name: str |
| 28 | + _identity: LambdaCognitoIdentity |
| 29 | + _client_context: LambdaClientContext |
| 30 | + |
| 31 | + @property |
| 32 | + def function_name(self) -> str: |
| 33 | + """The name of the Lambda function.""" |
| 34 | + return self._function_name |
| 35 | + |
| 36 | + @property |
| 37 | + def function_version(self) -> str: |
| 38 | + """The version of the function.""" |
| 39 | + return self._function_version |
| 40 | + |
| 41 | + @property |
| 42 | + def invoked_function_arn(self) -> str: |
| 43 | + """The Amazon Resource Name (ARN) that's used to invoke the function. Indicates if the invoker specified a |
| 44 | + version number or alias.""" |
| 45 | + return self._invoked_function_arn |
| 46 | + |
| 47 | + @property |
| 48 | + def memory_limit_in_mb(self) -> int: |
| 49 | + """The amount of memory that's allocated for the function.""" |
| 50 | + return self._memory_limit_in_mb |
| 51 | + |
| 52 | + @property |
| 53 | + def aws_request_id(self) -> str: |
| 54 | + """The identifier of the invocation request.""" |
| 55 | + return self._aws_request_id |
| 56 | + |
| 57 | + @property |
| 58 | + def log_group_name(self) -> str: |
| 59 | + """The log group for the function.""" |
| 60 | + return self._log_group_name |
| 61 | + |
| 62 | + @property |
| 63 | + def log_stream_name(self) -> str: |
| 64 | + """The log stream for the function instance.""" |
| 65 | + return self._log_stream_name |
| 66 | + |
| 67 | + @property |
| 68 | + def identity(self) -> LambdaCognitoIdentity: |
| 69 | + """(mobile apps) Information about the Amazon Cognito identity that authorized the request.""" |
| 70 | + return self._identity |
| 71 | + |
| 72 | + @property |
| 73 | + def client_context(self) -> LambdaClientContext: |
| 74 | + """(mobile apps) Client context that's provided to Lambda by the client application.""" |
| 75 | + return self._client_context |
| 76 | + |
| 77 | + @staticmethod |
| 78 | + def get_remaining_time_in_millis() -> int: |
| 79 | + """Returns the number of milliseconds left before the execution times out.""" |
| 80 | + return 0 |
0 commit comments