@@ -48,6 +48,7 @@ def __init__(
4848 environment : dict [str , str ] | None = None ,
4949 logging_config : awslambda .LoggingConfig | None = None ,
5050 dl_config : awslambda .DeadLetterConfig | None = None ,
51+ vpc_config : awslambda .VPCConfig | None = None ,
5152 ):
5253 """Initialize an AWS lambda function.
5354
@@ -76,6 +77,10 @@ def __init__(
7677 :param logging_config: The function's Amazon CloudWatch Logs settings
7778 :param dl_config: The dead letter config that specifies the topic or queue where
7879 lambda sends asynchronous events when they fail processing
80+ :param vpc_config: For network connectivity to AWS resources in a VPC, specify
81+ a list of security groups and subnets in the VPC. When you connect a
82+ function to a VPC, it can access resources and the internet only
83+ through that VPC
7984 """
8085 self .name = name
8186 self .description = description
@@ -94,6 +99,7 @@ def __init__(
9499 self .environment = environment
95100 self .logging_config = logging_config
96101 self .dl_config = dl_config
102+ self .vpc_config = vpc_config
97103
98104 def cfn_policy_document (self , stack : Stack ) -> PolicyDocument :
99105 statements = [
@@ -209,6 +215,9 @@ def lambda_resources(
209215 if self .dl_config is not None :
210216 params ["DeadLetterConfig" ] = self .dl_config
211217
218+ if self .vpc_config is not None :
219+ params ["VpcConfig" ] = self .vpc_config
220+
212221 result = [awslambda .Function (name_to_id (self .name ), ** params )]
213222 # If retention duration is given provide a log group.
214223 # If not provided the lambda creates a log group with
@@ -392,6 +401,7 @@ def __init__(
392401 environment : dict [str , str ] | None = None ,
393402 logging_config : awslambda .LoggingConfig | None = None ,
394403 dl_config : awslambda .DeadLetterConfig | None = None ,
404+ vpc_config : awslambda .VPCConfig | None = None ,
395405 ):
396406 """Initialize an AWS lambda function with a Python runtime.
397407
@@ -420,6 +430,10 @@ def __init__(
420430 :param logging_config: The function's Amazon CloudWatch Logs settings
421431 :param dl_config: The dead letter config that specifies the topic or queue where
422432 lambda sends asynchronous events when they fail processing
433+ :param vpc_config: For network connectivity to AWS resources in a VPC, specify
434+ a list of security groups and subnets in the VPC. When you connect a
435+ function to a VPC, it can access resources and the internet only
436+ through that VPC
423437 """
424438 assert runtime .startswith ("python" ), "PyFunction only accept Python runtimes"
425439 super ().__init__ (
@@ -439,6 +453,7 @@ def __init__(
439453 environment = environment ,
440454 logging_config = logging_config ,
441455 dl_config = dl_config ,
456+ vpc_config = vpc_config ,
442457 )
443458 self .code_dir = code_dir
444459 self .requirement_file = requirement_file
0 commit comments