feat: support creating a Lambda function/step from an ECR image (#4819) - #6349
mohamedzeidan2021 wants to merge 1 commit into
Conversation
|
Claude finished @mohamedzeidan2021's task in 1m 11s —— View job Code Review: Lambda from ECR image (#4819)Reviewed Summary: The 🟠 The
|
lucasjia-aws
left a comment
There was a problem hiding this comment.
Automated review: 1 blocking issue found (backward compatibility of Lambda.__init__ signature). See inline comment.
| zipped_code_dir: str = None, | ||
| s3_bucket: str = None, | ||
| script: str = None, | ||
| image: str = None, |
There was a problem hiding this comment.
[blocker] backward-compat
The new image parameter is inserted between script and handler rather than appended to the end of the signature. This shifts the positional binding of every subsequent parameter (handler, session, timeout, memory_size, runtime, vpc_config, environment, layers), so any existing caller that passes handler (or a later arg) positionally now silently binds that value to image. Positional argument order is public API contract for pip install sagemaker users. Append image after the existing parameters instead:
def __init__(
self,
...
layers: list = None,
image: str = None,
):|
Thanks for this — the One gap worth addressing before merge, tied to the "step" in the title / the linked issue (#4819, which is specifically about creating a Lambda step from an ECR image):
if self.lambda_func.zipped_code_dir is None and self.lambda_func.script is None:
warnings.warn("Lambda function won't be updated because zipped_code_dir or script is not provided.")
return self.lambda_func.function_arn
response = self.lambda_func.update()So for an image-based Suggested fix — include if (self.lambda_func.zipped_code_dir is None
and self.lambda_func.script is None
and self.lambda_func.image is None):
warnings.warn(...)
return self.lambda_func.function_arnPlus a A few minor, non-blocking items:
|
Problem
The
Lambdahelper (sagemaker.core.lambda_helper.Lambda) could only create/update functions from a zipped script or an S3 zip. It always sentRuntime+Handlerand built aZipFile/S3Codeblock, so there was no way to deploy a Lambda from an ECR container image (PackageType="Image"), which boto3'screate_functionsupports natively.Fix
image: str = Noneparameter toLambda.__init__(stored asself.image).script/zipped_code_dir/image), rejects combiningimagewith the others, and no longer requireshandlerwhenimageis used.create(): whenimageis set, callscreate_function(FunctionName, Role, Code={"ImageUri": image}, PackageType="Image", Timeout, MemorySize, VpcConfig, Environment, Layers)— omittingRuntime/Handler. Existing zip/S3 paths unchanged.update(): whenimageis set, callsupdate_function_code(FunctionName, ImageUri=image).imagedefaults toNone; existing behavior is untouched.Testing
Added unit tests in
tests/unit/test_lambda_helper.pycovering image-based init (stores image, no handler needed), image+script / image+zip validation errors, image create (assertsCode={"ImageUri":...},PackageType="Image", and noRuntime/Handler), image create error handling, and image update. Full module: 34 passed.black+flake8clean.Fixes #4819