diff --git a/doc/api/inference/model.rst b/doc/api/inference/model.rst index 2846c58d0b..a975086162 100644 --- a/doc/api/inference/model.rst +++ b/doc/api/inference/model.rst @@ -15,3 +15,8 @@ Model :members: :undoc-members: :show-inheritance: + +.. autoclass:: sagemaker.serverless.model.LambdaModel + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/api/inference/predictors.rst b/doc/api/inference/predictors.rst index 6a9243f329..66ffcf45be 100644 --- a/doc/api/inference/predictors.rst +++ b/doc/api/inference/predictors.rst @@ -7,3 +7,8 @@ Make real-time predictions against SageMaker endpoints with Python objects :members: :undoc-members: :show-inheritance: + +.. autoclass:: sagemaker.serverless.predictor.LambdaPredictor + :members: + :undoc-members: + :show-inheritance: diff --git a/doc/overview.rst b/doc/overview.rst index 02290ff94c..2085abd24d 100644 --- a/doc/overview.rst +++ b/doc/overview.rst @@ -1063,6 +1063,50 @@ You can also find these notebooks in the **Advanced Functionality** section of t For information about using sample notebooks in a SageMaker notebook instance, see `Use Example Notebooks `__ in the AWS documentation. +******************** +Serverless Inference +******************** + +You can use the SageMaker Python SDK to perform serverless inference on Lambda. + +To deploy models to Lambda, you must complete the following prerequisites: + +- `Package your model and inference code as a container image. `_ +- `Create a role that lists Lambda as a trusted entity. `_ + +After completing the prerequisites, you can deploy your model to Lambda using +the `LambdaModel`_ class. + +.. code:: python + + from sagemaker.serverless import LambdaModel + + image_uri = "123456789012.dkr.ecr.us-west-2.amazonaws.com/my-lambda-repository:latest" + role = "arn:aws:iam::123456789012:role/MyLambdaExecutionRole" + + model = LambdaModel(image_uri=image_uri, role=role) + predictor = model.deploy("my-lambda-function", timeout=20, memory_size=4092) + +The ``deploy`` method returns a `LambdaPredictor`_ instance. Use the +`LambdaPredictor`_ ``predict`` method to perform inference on Lambda. + +.. code:: python + + url = "https://example.com/cat.jpeg" + predictor.predict({"url": url}) # {'class': 'tabby'} + +Once you are done performing inference on Lambda, free the `LambdaModel`_ and +`LambdaPredictor`_ resources using the ``delete_model`` and ``delete_predictor`` +methods. + +.. code:: python + + model.delete_model() + predictor.delete_predictor() + +.. _LambdaModel : https://sagemaker.readthedocs.io/en/stable/api/inference/model.html#sagemaker.serverless.model.LambdaModel +.. _LambdaPredictor : https://sagemaker.readthedocs.io/en/stable/api/inference/predictors.html#sagemaker.serverless.predictor.LambdaPredictor + ****************** SageMaker Workflow ******************