Skip to content

Commit 07443bb

Browse files
committed
feature: Add VpcConfig, Architectures and Environment parameters for CreateLambda operation
1 parent 7faf9ce commit 07443bb

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

src/sagemaker/lambda_helper.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def __init__(
3636
timeout: int = 120,
3737
memory_size: int = 128,
3838
runtime: str = "python3.8",
39+
vpc_config: dict = None,
40+
architectures: list = None,
41+
environment: dict = None,
3942
):
4043
"""Constructs a Lambda instance.
4144
@@ -66,6 +69,10 @@ def __init__(
6669
timeout (int): Timeout of the Lambda function in seconds. Default is 120 seconds.
6770
memory_size (int): Memory of the Lambda function in megabytes. Default is 128 MB.
6871
runtime (str): Runtime of the Lambda function. Default is set to python3.8.
72+
vpc_config (dict): VPC to deploy the Lambda function to. Default is None.
73+
architectures (list): Which architecture to deploy to. Valid Values are
74+
'x86_64' and 'arm64', default is None.
75+
environment (dict): Environment Variables for the Lambda function. Default is None.
6976
"""
7077
self.function_arn = function_arn
7178
self.function_name = function_name
@@ -78,6 +85,9 @@ def __init__(
7885
self.timeout = timeout
7986
self.memory_size = memory_size
8087
self.runtime = runtime
88+
self.vpc_config = vpc_config
89+
self.environment = environment
90+
self.architectures = architectures
8191

8292
if function_arn is None and function_name is None:
8393
raise ValueError("Either function_arn or function_name must be provided.")
@@ -123,6 +133,9 @@ def create(self):
123133
Code=code,
124134
Timeout=self.timeout,
125135
MemorySize=self.memory_size,
136+
VpcConfig=self.vpc_config,
137+
Environment=self.environment,
138+
Architectures=self.architectures,
126139
)
127140
return response
128141
except ClientError as e:
@@ -152,6 +165,7 @@ def update(self):
152165
zipped_code_dir=self.zipped_code_dir,
153166
s3_bucket=self.s3_bucket,
154167
),
168+
Architectures=self.architectures
155169
)
156170
return response
157171
except ClientError as e:

tests/unit/test_lambda_helper.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,12 @@ def test_upsert_lambda_happycase1(sagemaker_session):
302302
script=SCRIPT,
303303
handler=HANDLER,
304304
session=sagemaker_session,
305+
architectures=["x86_64"],
306+
environment={"Name": "my-test-lambda"},
307+
vpc_config={
308+
"SubnetIds": ["test-subnet-1"],
309+
"SecurityGroupIds": ["sec-group-1"]
310+
}
305311
)
306312

307313
code = {"ZipFile": ZIPPED_CODE}
@@ -315,6 +321,12 @@ def test_upsert_lambda_happycase1(sagemaker_session):
315321
Code=code,
316322
Timeout=120,
317323
MemorySize=128,
324+
Architectures=["x86_64"],
325+
Environment={"Name": "my-test-lambda"},
326+
VpcConfig={
327+
"SubnetIds": ["test-subnet-1"],
328+
"SecurityGroupIds": ["sec-group-1"]
329+
}
318330
)
319331

320332

@@ -326,6 +338,7 @@ def test_upsert_lambda_happycase2(sagemaker_session):
326338
script=SCRIPT,
327339
handler=HANDLER,
328340
session=sagemaker_session,
341+
architectures=["x86_64"]
329342
)
330343

331344
sagemaker_session.lambda_client.create_function.side_effect = ClientError(
@@ -336,7 +349,7 @@ def test_upsert_lambda_happycase2(sagemaker_session):
336349
lambda_obj.upsert()
337350

338351
sagemaker_session.lambda_client.update_function_code.assert_called_once_with(
339-
FunctionName=FUNCTION_NAME, ZipFile=ZIPPED_CODE
352+
FunctionName=FUNCTION_NAME, ZipFile=ZIPPED_CODE, Architectures=["x86_64"]
340353
)
341354

342355

0 commit comments

Comments
 (0)