Skip to content
This repository has been archived by the owner on Aug 26, 2024. It is now read-only.

Add app template supported AWS lambda s3 event-based predictions #164

Merged
merged 6 commits into from
Sep 18, 2022

Conversation

cosmicBboy
Copy link
Contributor

Fixes #19

This PR creates a unionml app template that can be instantiated with unionml init --template basic-aws-lambda-s3 APP_NAME, which ships with the necessary SAM template, app code, handler code, and basic unit tests for users to get started with s3-event-based predictions.

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>
Copy link
Contributor

@eapolinario eapolinario left a comment

Choose a reason for hiding this comment

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

looking good. Left 2 comments, nothing major.

Comment on lines +34 to +38
# upload predictions to s3
out_filename = "/tmp/predictions.json"
with open(out_filename, "w") as f:
json.dump(predictions, f)

Copy link
Contributor

Choose a reason for hiding this comment

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

any reason not to use another NamedTemporaryFile for the predictions as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it somehow wasn't working, the file uploaded to s3 would be empty 🤷‍♂️


assert ret is None
mock_dl_file.assert_called_once()
mock_ul_file.assert_called_once()
Copy link
Contributor

Choose a reason for hiding this comment

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

is there anyway we could capture the content of the file being written to s3? Just to double-check we're writing the right predictions.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

lemme try something

Signed-off-by: Niels Bantilan <niels.bantilan@gmail.com>

# Reacting to S3 Events

In {ref}`serving_aws_lambda` we learned how to deploy a prediction service to an AWS
Copy link
Contributor

Choose a reason for hiding this comment

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

so this is how you cross reference docs in markdown.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

actually using https://myst-parser.readthedocs.io/en/latest/ for these docs... we should move Flyte (incrementally) to this, it's a lot easier to write docs for

def load_from_env(self, env_var: str = "UNIONML_MODEL_PATH", *args, **kwargs):
"""Load a model object from an environment variable pointing to the model file.

:env_var: environment variable referencing a path to load a model from.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: missing param before env_var.

with tempfile.NamedTemporaryFile("w") as out_file:
json.dump(predictions, out_file)
upload_key = f"predictions/{key.split('/')[-1]}"
out_file.flush()
Copy link
Contributor

Choose a reason for hiding this comment

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

nice.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

AWS Lambda event-based s3 event serving support
2 participants