Skip to content

Commit 12c222b

Browse files
documentation: Document LambdaModel and LambdaPredictor classes (#2558)
Co-authored-by: Ahsan Khan <[email protected]>
1 parent 62294fd commit 12c222b

File tree

3 files changed

+54
-0
lines changed

3 files changed

+54
-0
lines changed

doc/api/inference/model.rst

+5
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ Model
1515
:members:
1616
:undoc-members:
1717
:show-inheritance:
18+
19+
.. autoclass:: sagemaker.serverless.model.LambdaModel
20+
:members:
21+
:undoc-members:
22+
:show-inheritance:

doc/api/inference/predictors.rst

+5
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,8 @@ Make real-time predictions against SageMaker endpoints with Python objects
77
:members:
88
:undoc-members:
99
:show-inheritance:
10+
11+
.. autoclass:: sagemaker.serverless.predictor.LambdaPredictor
12+
:members:
13+
:undoc-members:
14+
:show-inheritance:

doc/overview.rst

+44
Original file line numberDiff line numberDiff line change
@@ -1063,6 +1063,50 @@ You can also find these notebooks in the **Advanced Functionality** section of t
10631063
For information about using sample notebooks in a SageMaker notebook instance, see `Use Example Notebooks <https://docs.aws.amazon.com/sagemaker/latest/dg/howitworks-nbexamples.html>`__
10641064
in the AWS documentation.
10651065
1066+
********************
1067+
Serverless Inference
1068+
********************
1069+
1070+
You can use the SageMaker Python SDK to perform serverless inference on Lambda.
1071+
1072+
To deploy models to Lambda, you must complete the following prerequisites:
1073+
1074+
- `Package your model and inference code as a container image. <https://docs.aws.amazon.com/lambda/latest/dg/images-create.html>`_
1075+
- `Create a role that lists Lambda as a trusted entity. <https://docs.aws.amazon.com/lambda/latest/dg/lambda-intro-execution-role.html#permissions-executionrole-console>`_
1076+
1077+
After completing the prerequisites, you can deploy your model to Lambda using
1078+
the `LambdaModel`_ class.
1079+
1080+
.. code:: python
1081+
1082+
from sagemaker.serverless import LambdaModel
1083+
1084+
image_uri = "123456789012.dkr.ecr.us-west-2.amazonaws.com/my-lambda-repository:latest"
1085+
role = "arn:aws:iam::123456789012:role/MyLambdaExecutionRole"
1086+
1087+
model = LambdaModel(image_uri=image_uri, role=role)
1088+
predictor = model.deploy("my-lambda-function", timeout=20, memory_size=4092)
1089+
1090+
The ``deploy`` method returns a `LambdaPredictor`_ instance. Use the
1091+
`LambdaPredictor`_ ``predict`` method to perform inference on Lambda.
1092+
1093+
.. code:: python
1094+
1095+
url = "https://example.com/cat.jpeg"
1096+
predictor.predict({"url": url}) # {'class': 'tabby'}
1097+
1098+
Once you are done performing inference on Lambda, free the `LambdaModel`_ and
1099+
`LambdaPredictor`_ resources using the ``delete_model`` and ``delete_predictor``
1100+
methods.
1101+
1102+
.. code:: python
1103+
1104+
model.delete_model()
1105+
predictor.delete_predictor()
1106+
1107+
.. _LambdaModel : https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.serverless.model.LambdaModel
1108+
.. _LambdaPredictor : https://sagemaker.readthedocs.io/en/stable/api/inference/predictors.html#sagemaker.serverless.predictor.LambdaPredictor
1109+
10661110
******************
10671111
SageMaker Workflow
10681112
******************

0 commit comments

Comments
 (0)