aws-lambda-env-modeler 1.0.1__tar.gz → 1.0.3__tar.gz
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_env_modeler-1.0.1 → aws_lambda_env_modeler-1.0.3}/PKG-INFO +5 -6
- {aws_lambda_env_modeler-1.0.1 → aws_lambda_env_modeler-1.0.3}/README.md +3 -4
- aws_lambda_env_modeler-1.0.3/aws_lambda_env_modeler/__init__.py +13 -0
- aws_lambda_env_modeler-1.0.3/aws_lambda_env_modeler/modeler.py +65 -0
- aws_lambda_env_modeler-1.0.3/aws_lambda_env_modeler/types.py +7 -0
- {aws_lambda_env_modeler-1.0.1 → aws_lambda_env_modeler-1.0.3}/pyproject.toml +5 -4
- {aws_lambda_env_modeler-1.0.1 → aws_lambda_env_modeler-1.0.3}/LICENSE +0 -0
- {aws_lambda_env_modeler-1.0.1 → aws_lambda_env_modeler-1.0.3}/aws_lambda_env_modeler/py.typed +0 -0
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: aws-lambda-env-modeler
|
|
3
|
-
Version: 1.0.
|
|
3
|
+
Version: 1.0.3
|
|
4
4
|
Summary: AWS-Lambda-Env-Modeler is a Python library designed to simplify the process of managing and validating environment variables in your AWS Lambda functions.
|
|
5
5
|
Home-page: https://github.com/ran-isenberg/aws-lambda-env-modeler
|
|
6
6
|
License: MIT-0
|
|
7
|
-
Keywords: environment variables parser,aws lambda,serverless best practices,aws serverless
|
|
7
|
+
Keywords: environment variables parser,aws lambda,serverless best practices,aws serverless,lambda environment variables
|
|
8
8
|
Author: Ran Isenberg
|
|
9
9
|
Requires-Python: >=3.8.17,<4.0.0
|
|
10
10
|
Classifier: Development Status :: 5 - Production/Stable
|
|
@@ -27,12 +27,11 @@ Description-Content-Type: text/markdown
|
|
|
27
27
|
# AWS Lambda Environment Variables Modeler (Python)
|
|
28
28
|
|
|
29
29
|
[](https://github.com/ran-isenberg/aws-lambda-env-modeler/blob/master/LICENSE)
|
|
30
|
-

|
|
31
|
+

|
|
32
|
+

|
|
33
33
|
[](https://codecov.io/gh/ran-isenberg/aws-lambda-env-modeler)
|
|
34
34
|

|
|
35
|
-

|
|
36
35
|

|
|
37
36
|

|
|
38
37
|
|
|
@@ -2,12 +2,11 @@
|
|
|
2
2
|
# AWS Lambda Environment Variables Modeler (Python)
|
|
3
3
|
|
|
4
4
|
[](https://github.com/ran-isenberg/aws-lambda-env-modeler/blob/master/LICENSE)
|
|
5
|
-

|
|
6
|
+

|
|
7
|
+

|
|
8
8
|
[](https://codecov.io/gh/ran-isenberg/aws-lambda-env-modeler)
|
|
9
9
|

|
|
10
|
-

|
|
11
10
|

|
|
12
11
|

|
|
13
12
|
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Advanced event_parser utility
|
|
2
|
+
"""
|
|
3
|
+
from pydantic import BaseModel
|
|
4
|
+
|
|
5
|
+
from .modeler import get_environment_variables, init_environment_variables
|
|
6
|
+
from .types import Model
|
|
7
|
+
|
|
8
|
+
__all__ = [
|
|
9
|
+
'Model',
|
|
10
|
+
'BaseModel',
|
|
11
|
+
'init_environment_variables',
|
|
12
|
+
'get_environment_variables',
|
|
13
|
+
]
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import os
|
|
2
|
+
from functools import lru_cache, wraps
|
|
3
|
+
from typing import Any, Callable, Dict, Type
|
|
4
|
+
|
|
5
|
+
from aws_lambda_env_modeler.types import Model
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def get_environment_variables(model: Type[Model]) -> Model:
|
|
9
|
+
"""
|
|
10
|
+
This function receives a model of type Model, uses it to validate the environment variables, and returns the
|
|
11
|
+
validated model.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
model (Type[Model]): A Pydantic model that defines the structure and types of the expected environment variables.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
Model: An instance of the provided model filled with the values of the validated environment variables.
|
|
18
|
+
"""
|
|
19
|
+
return __parse_model(model)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def init_environment_variables(model: Type[Model]):
|
|
23
|
+
"""
|
|
24
|
+
A decorator function for AWS Lambda handler functions that initializes environment variables based on the given Pydantic model before executing
|
|
25
|
+
the decorated function. The decorator validates the environment variables according to the model structure before
|
|
26
|
+
running the handler.
|
|
27
|
+
|
|
28
|
+
Args:
|
|
29
|
+
model (Type[Model]): A Pydantic model that defines the structure and types of the expected environment variables.
|
|
30
|
+
|
|
31
|
+
Returns:
|
|
32
|
+
Callable: A decorated function that first initializes the environment variables and then runs the function.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
def decorator(lambda_handler_function: Callable):
|
|
36
|
+
|
|
37
|
+
@wraps(lambda_handler_function)
|
|
38
|
+
def wrapper(event: Dict[str, Any], context):
|
|
39
|
+
__parse_model(model)
|
|
40
|
+
return lambda_handler_function(event, context)
|
|
41
|
+
|
|
42
|
+
return wrapper
|
|
43
|
+
|
|
44
|
+
return decorator
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@lru_cache
|
|
48
|
+
def __parse_model(model: Type[Model]) -> Model:
|
|
49
|
+
"""
|
|
50
|
+
A helper function to validate and parse environment variables based on a given Pydantic model. This function is
|
|
51
|
+
also cached to improve performance in successive calls.
|
|
52
|
+
|
|
53
|
+
Args:
|
|
54
|
+
model (Type[Model]): A Pydantic model that defines the structure and types of the expected environment variables.
|
|
55
|
+
|
|
56
|
+
Returns:
|
|
57
|
+
Model: An instance of the provided model filled with the values of the validated environment variables.
|
|
58
|
+
|
|
59
|
+
Raises:
|
|
60
|
+
ValueError: If the environment variables do not match the structure of the model or cannot be validated.
|
|
61
|
+
"""
|
|
62
|
+
try:
|
|
63
|
+
return model.model_validate(os.environ)
|
|
64
|
+
except Exception as exc:
|
|
65
|
+
raise ValueError(f'failed to load environment variables, exception={str(exc)}') from exc
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "aws_lambda_env_modeler"
|
|
3
|
-
version = "1.0.
|
|
3
|
+
version = "1.0.3"
|
|
4
4
|
description = "AWS-Lambda-Env-Modeler is a Python library designed to simplify the process of managing and validating environment variables in your AWS Lambda functions."
|
|
5
5
|
authors = ["Ran Isenberg"]
|
|
6
6
|
classifiers=[
|
|
@@ -11,13 +11,14 @@ classifiers=[
|
|
|
11
11
|
"Programming Language :: Python :: 3.8",
|
|
12
12
|
"Programming Language :: Python :: 3.9",
|
|
13
13
|
"Programming Language :: Python :: 3.10",
|
|
14
|
+
"Programming Language :: Python :: 3.11",
|
|
14
15
|
]
|
|
15
16
|
repository="https://github.com/ran-isenberg/aws-lambda-env-modeler"
|
|
16
17
|
readme = "README.md"
|
|
17
|
-
keywords = ["environment variables parser", "aws lambda", "serverless best practices", "aws serverless"]
|
|
18
|
+
keywords = ["environment variables parser", "aws lambda", "serverless best practices", "aws serverless", "lambda environment variables"]
|
|
18
19
|
license = "MIT-0"
|
|
19
20
|
packages = [
|
|
20
|
-
{ include = "aws_lambda_env_modeler
|
|
21
|
+
{ include = "aws_lambda_env_modeler" }]
|
|
21
22
|
|
|
22
23
|
[tool.poetry.urls]
|
|
23
24
|
"Issue tracker" = "https://github.com/ran-isenberg/aws-lambda-env-modeler/issues"
|
|
@@ -25,7 +26,7 @@ packages = [
|
|
|
25
26
|
|
|
26
27
|
|
|
27
28
|
[tool.poetry.dependencies]
|
|
28
|
-
python = "^3.8.17"
|
|
29
|
+
python = "^3.8.17 || ^3.9.0 || ^3.10.0 || ^3.11.0"
|
|
29
30
|
pydantic = {version = "^2.0.0"}
|
|
30
31
|
|
|
31
32
|
[tool.poetry.dev-dependencies]
|
|
File without changes
|
{aws_lambda_env_modeler-1.0.1 → aws_lambda_env_modeler-1.0.3}/aws_lambda_env_modeler/py.typed
RENAMED
|
File without changes
|