Skip to content

Fix: hardcode handler_name = "lambda_function.lambda_handler" to match the zip entry name.#5692

Open
mollyheamazon wants to merge 3 commits intoaws:masterfrom
mollyheamazon:fix/lambda_handler
Open

Fix: hardcode handler_name = "lambda_function.lambda_handler" to match the zip entry name.#5692
mollyheamazon wants to merge 3 commits intoaws:masterfrom
mollyheamazon:fix/lambda_handler

Conversation

@mollyheamazon
Copy link
Copy Markdown
Contributor

Issue #, if available:
Ticket: https://tiny.amazon.com/12ooeo0ys/tcorpamazP405over

Description of changes:

  • One-line fix in evaluator.py line 385
  • Updated test_create_with_byoc to assert the correct Handler value is passed to create_function

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link
Copy Markdown
Member

@mufaddal-rohawala mufaddal-rohawala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI Code Review

This PR fixes a bug where the Lambda handler name was dynamically derived from the source file name, but the zip entry always uses 'lambda_function.py' as the module name. The fix is straightforward and the test update correctly validates the new behavior. However, there are two notable concerns: a direct boto3 call (pre-existing) and a missing explanation of why the handler name must be hardcoded.

lambda_client = boto3.client("lambda")
function_name = f"SageMaker-evaluator-{name}-{datetime.now().strftime('%Y%m%d_%H%M%S')}"
handler_name = f"{os.path.splitext(os.path.basename(source_file))[0]}.lambda_handler"
handler_name = "lambda_function.lambda_handler"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The fix itself makes sense if the zip archive always packages the source file as lambda_function.py regardless of the original filename. However, this introduces a subtle coupling — the hardcoded string "lambda_function.lambda_handler" must match whatever entry name is used when building the zip. Consider extracting this as a module-level constant (e.g., LAMBDA_HANDLER_NAME = "lambda_function.lambda_handler") and adding a comment explaining why it's hardcoded (i.e., the zip archive always renames the source to lambda_function.py). This will prevent future contributors from "fixing" it back to the dynamic version.

Also, as a pre-existing issue: this method calls boto3.client("lambda") directly (line 383). Per V3 architecture tenets, all AWS API interactions should go through sagemaker-core rather than calling boto3 directly. This is out of scope for this PR, but worth tracking.

@mollyheamazon
Copy link
Copy Markdown
Contributor Author

mlops integ test failures is flaky test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants