Skip to content

Commit d044eac

Browse files
Add context dictionary support to lambda
** Why are these changes being introduced: * At the moment, running the curl command from the project readme in a terminal results in an argument error, rather than the stated response. ** Relevant ticket(s): n/a ** How does this address that need: * This adds a second dictionary as an argument to the lambda_handler method in predict.py. The same change is made to the two tests which actually call this fuction. This now matches what the s3-bagit lambda is expecting, which I'm using as a starting point for my work in this repo: Handler: https://github.com/MITLibraries/s3-bagit-validator/blob/main/lambdas/validator.py#L29 Test: https://github.com/MITLibraries/s3-bagit-validator/blob/main/tests/test_lambda_handler.py#L20 ** Document any side effects to this change: I'm not sure whether this is going to bite me later or not - that will need to wait until this gets deployed to AWS.
1 parent 8104a76 commit d044eac

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lambdas/predict.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
logger.info("No Sentry DSN found, exceptions will not be sent to Sentry")
2424

2525

26-
def lambda_handler(event: dict) -> str:
26+
def lambda_handler(event: dict, _context: dict) -> str:
2727
if not os.getenv("WORKSPACE"):
2828
unset_workspace_error_message = "Required env variable WORKSPACE is not set"
2929
raise RuntimeError(unset_workspace_error_message)

tests/test_predict.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ def test_predict_doesnt_configure_sentry_if_dsn_not_present(caplog, monkeypatch)
2222
def test_lambda_handler_missing_workspace_env_raises_error(monkeypatch):
2323
monkeypatch.delenv("WORKSPACE", raising=False)
2424
with pytest.raises(RuntimeError) as error:
25-
predict.lambda_handler({})
25+
predict.lambda_handler({}, {})
2626
assert "Required env variable WORKSPACE is not set" in str(error)
2727

2828

2929
def test_predict():
30-
assert predict.lambda_handler({}) == "You have successfully called this lambda!"
30+
assert predict.lambda_handler({}, {}) == "You have successfully called this lambda!"

0 commit comments

Comments
 (0)