1
1
import io
2
2
import os
3
+ import sys
3
4
import zipfile
5
+ from enum import Enum
4
6
from pathlib import Path
5
7
6
8
import boto3
7
9
import yaml
8
10
from aws_cdk import App , CfnOutput , RemovalPolicy , Stack , aws_lambda_python_alpha , aws_logs
9
11
from aws_cdk .aws_lambda import Code , Function , Runtime , Tracing
10
12
13
+ PYTHON_RUNTIME_VERSION = f"V{ '' .join (map (str , sys .version_info [:2 ]))} "
14
+
15
+
16
+ class PythonVersion (Enum ):
17
+ V37 = Runtime .PYTHON_3_7
18
+ V38 = Runtime .PYTHON_3_8
19
+ V39 = Runtime .PYTHON_3_9
20
+
11
21
12
22
class Infrastructure :
13
23
def __init__ (self , stack_name : str , handlers_dir : str , config : dict , environment_variables : dict ) -> None :
@@ -63,7 +73,7 @@ def _prepare_stack(self, handlers, handlers_dir, stack_name, environment_variabl
63
73
"aws-lambda-powertools" ,
64
74
layer_version_name = "aws-lambda-powertools" ,
65
75
entry = "." ,
66
- compatible_runtimes = [Runtime . PYTHON_3_9 ],
76
+ compatible_runtimes = [PythonVersion [ PYTHON_RUNTIME_VERSION ]. value ],
67
77
)
68
78
code = Code .from_asset (handlers_dir )
69
79
@@ -72,7 +82,7 @@ def _prepare_stack(self, handlers, handlers_dir, stack_name, environment_variabl
72
82
function_python = Function (
73
83
stack ,
74
84
f"{ filename } -lambda" ,
75
- runtime = Runtime . PYTHON_3_9 ,
85
+ runtime = PythonVersion [ PYTHON_RUNTIME_VERSION ]. value ,
76
86
code = code ,
77
87
handler = f"{ filename } .lambda_handler" ,
78
88
layers = [powertools_layer ],
0 commit comments