BentoML Example: Sentiment Analysis with Scikit-learn

BentoML is an open source framework for building, shipping and running machine learning services. It provides high-level APIs for defining an ML service and packaging its artifacts, source code, dependencies, and configurations into a production-system-friendly format that is ready for deployment.

This notebook demonstrates how to use BentoML to turn a scikit-learn model into a docker image containing a REST API server serving this model, how to use your ML service built with BentoML as a CLI tool, and how to distribute it a pypi package.

The example is based on this notebook, using dataset from Sentiment140

Impression

In [57]:
%reload_ext autoreload
%autoreload 2
%matplotlib inline 
In [2]:
!pip bentoml
!pip install sklearn pandas numpy
Requirement already satisfied: sklearn in /usr/local/anaconda3/lib/python3.6/site-packages (0.0)
Requirement already satisfied: pandas in /usr/local/anaconda3/lib/python3.6/site-packages (0.22.0)
Requirement already satisfied: numpy in /usr/local/anaconda3/lib/python3.6/site-packages (1.16.4)
Requirement already satisfied: scikit-learn in /usr/local/anaconda3/lib/python3.6/site-packages (from sklearn) (0.19.1)
Requirement already satisfied: python-dateutil>=2 in /usr/local/anaconda3/lib/python3.6/site-packages (from pandas) (2.6.1)
Requirement already satisfied: pytz>=2011k in /usr/local/anaconda3/lib/python3.6/site-packages (from pandas) (2017.3)
Requirement already satisfied: six>=1.5 in /usr/local/anaconda3/lib/python3.6/site-packages (from python-dateutil>=2->pandas) (1.11.0)
You are using pip version 18.1, however version 20.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
In [58]:
import numpy as np
import pandas as pd
from sklearn.feature_extraction.text import CountVectorizer
from sklearn.linear_model import LogisticRegression
from sklearn.metrics import classification_report, roc_auc_score, roc_curve
from sklearn.pipeline import Pipeline

import bentoml

Prepare Dataset

In [59]:
%%bash

if [ ! -f ./trainingandtestdata.zip ]; then
    wget -q http://cs.stanford.edu/people/alecmgo/trainingandtestdata.zip
    unzip -n trainingandtestdata.zip
fi
In [60]:
columns = ['polarity', 'tweetid', 'date', 'query_name', 'user', 'text']
dftrain = pd.read_csv('training.1600000.processed.noemoticon.csv',
                      header = None,
                      encoding ='ISO-8859-1')
dftest = pd.read_csv('testdata.manual.2009.06.14.csv',
                     header = None,
                     encoding ='ISO-8859-1')
dftrain.columns = columns
dftest.columns = columns

Model Training

In [61]:
sentiment_lr = Pipeline([
                         ('count_vect', CountVectorizer(min_df = 100,
                                                        ngram_range = (1,2),
                                                        stop_words = 'english')), 
                         ('lr', LogisticRegression())])
sentiment_lr.fit(dftrain.text, dftrain.polarity)
/usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages/sklearn/linear_model/_logistic.py:939: ConvergenceWarning: lbfgs failed to converge (status=1):
STOP: TOTAL NO. of ITERATIONS REACHED LIMIT.

Increase the number of iterations (max_iter) or scale the data as shown in:
    https://scikit-learn.org/stable/modules/preprocessing.html.
Please also refer to the documentation for alternative solver options:
    https://scikit-learn.org/stable/modules/linear_model.html#logistic-regression
  extra_warning_msg=_LOGISTIC_SOLVER_CONVERGENCE_MSG)
Out[61]:
Pipeline(memory=None,
         steps=[('count_vect',
                 CountVectorizer(analyzer='word', binary=False,
                                 decode_error='strict',
                                 dtype=<class 'numpy.int64'>, encoding='utf-8',
                                 input='content', lowercase=True, max_df=1.0,
                                 max_features=None, min_df=100,
                                 ngram_range=(1, 2), preprocessor=None,
                                 stop_words='english', strip_accents=None,
                                 token_pattern='(?u)\\b\\w\\w+\\b',
                                 tokenizer=None, vocabulary=None)),
                ('lr',
                 LogisticRegression(C=1.0, class_weight=None, dual=False,
                                    fit_intercept=True, intercept_scaling=1,
                                    l1_ratio=None, max_iter=100,
                                    multi_class='auto', n_jobs=None,
                                    penalty='l2', random_state=None,
                                    solver='lbfgs', tol=0.0001, verbose=0,
                                    warm_start=False))],
         verbose=False)
In [62]:
Xtest, ytest = dftest.text[dftest.polarity!=2], dftest.polarity[dftest.polarity!=2]
print(classification_report(ytest,sentiment_lr.predict(Xtest)))
              precision    recall  f1-score   support

           0       0.87      0.82      0.84       177
           4       0.83      0.88      0.86       182

    accuracy                           0.85       359
   macro avg       0.85      0.85      0.85       359
weighted avg       0.85      0.85      0.85       359

In [63]:
sentiment_lr.predict([Xtest[0]])
Out[63]:
array([4])

Create BentoService for model serving

In [74]:
%%writefile sentiment_analysis_service.py
import pandas as pd
import bentoml
from bentoml.artifact import SklearnModelArtifact, PickleArtifact
from bentoml.handlers import DataframeHandler

@bentoml.artifacts([PickleArtifact('model')])
@bentoml.env(pip_dependencies=["scikit-learn", "pandas"])
class SKSentimentAnalysis(bentoml.BentoService):

    @bentoml.api(DataframeHandler, typ='series')
    def predict(self, series):
        """
        predict expects pandas.Series as input
        """        
        return self.artifacts.model.predict(series)
Overwriting sentiment_analysis_service.py

Save BentoService to file archive

In [75]:
# 1) import the custom BentoService defined above
from sentiment_analysis_service import SKSentimentAnalysis

# 2) `pack` it with required artifacts
bento_service = SKSentimentAnalysis()
bento_service.pack('model', sentiment_lr)

# 3) save your BentoSerivce to file archive
saved_path = bento_service.save()
[2020-01-29 21:09:02,989] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-29 21:09:03,037] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-29 21:09:03,071] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-29 21:09:43,590] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
running sdist
running egg_info
writing BentoML.egg-info/PKG-INFO
writing dependency_links to BentoML.egg-info/dependency_links.txt
writing entry points to BentoML.egg-info/entry_points.txt
writing requirements to BentoML.egg-info/requires.txt
writing top-level names to BentoML.egg-info/top_level.txt
reading manifest file 'BentoML.egg-info/SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'examples'
no previously-included directories found matching 'tests'
no previously-included directories found matching 'docs'
warning: no previously-included files matching '*~' found anywhere in distribution
warning: no previously-included files matching '*.pyo' found anywhere in distribution
warning: no previously-included files matching '.git' found anywhere in distribution
warning: no previously-included files matching '.ipynb_checkpoints' found anywhere in distribution
warning: no previously-included files matching '__pycache__' found anywhere in distribution
writing manifest file 'BentoML.egg-info/SOURCES.txt'
running check
warning: check: missing meta-data: if 'author' supplied, 'author_email' must be supplied too

creating BentoML-0.6.1+2.gefb0204.dirty
creating BentoML-0.6.1+2.gefb0204.dirty/BentoML.egg-info
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/bundler
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/clipper
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/configuration
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/aws_lambda
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/sagemaker
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/migrations
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/migrations/versions
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/proto
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/repository
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/server
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/server/static
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils/validator
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai
creating BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai/client
copying files to BentoML-0.6.1+2.gefb0204.dirty...
copying LICENSE -> BentoML-0.6.1+2.gefb0204.dirty
copying MANIFEST.in -> BentoML-0.6.1+2.gefb0204.dirty
copying README.md -> BentoML-0.6.1+2.gefb0204.dirty
copying pyproject.toml -> BentoML-0.6.1+2.gefb0204.dirty
copying setup.cfg -> BentoML-0.6.1+2.gefb0204.dirty
copying setup.py -> BentoML-0.6.1+2.gefb0204.dirty
copying versioneer.py -> BentoML-0.6.1+2.gefb0204.dirty
copying BentoML.egg-info/PKG-INFO -> BentoML-0.6.1+2.gefb0204.dirty/BentoML.egg-info
copying BentoML.egg-info/SOURCES.txt -> BentoML-0.6.1+2.gefb0204.dirty/BentoML.egg-info
copying BentoML.egg-info/dependency_links.txt -> BentoML-0.6.1+2.gefb0204.dirty/BentoML.egg-info
copying BentoML.egg-info/entry_points.txt -> BentoML-0.6.1+2.gefb0204.dirty/BentoML.egg-info
copying BentoML.egg-info/requires.txt -> BentoML-0.6.1+2.gefb0204.dirty/BentoML.egg-info
copying BentoML.egg-info/top_level.txt -> BentoML-0.6.1+2.gefb0204.dirty/BentoML.egg-info
copying bentoml/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml
copying bentoml/_version.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml
copying bentoml/alembic.ini -> BentoML-0.6.1+2.gefb0204.dirty/bentoml
copying bentoml/db.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml
copying bentoml/exceptions.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml
copying bentoml/service.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml
copying bentoml/service_env.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml
copying bentoml/artifact/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/fastai_model_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/h2o_model_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/keras_model_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/lightgbm_model_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/pickle_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/pytorch_model_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/sklearn_model_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/text_file_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/tf_savedmodel_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/artifact/xgboost_model_artifact.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/artifact
copying bentoml/bundler/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/bundler
copying bentoml/bundler/bundler.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/bundler
copying bentoml/bundler/config.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/bundler
copying bentoml/bundler/loader.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/bundler
copying bentoml/bundler/py_module_utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/bundler
copying bentoml/bundler/templates.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/bundler
copying bentoml/bundler/utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/bundler
copying bentoml/cli/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
copying bentoml/cli/aws_lambda.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
copying bentoml/cli/aws_sagemaker.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
copying bentoml/cli/bento.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
copying bentoml/cli/click_utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
copying bentoml/cli/config.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
copying bentoml/cli/deployment.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
copying bentoml/cli/utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/cli
copying bentoml/clipper/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/clipper
copying bentoml/configuration/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/configuration
copying bentoml/configuration/configparser.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/configuration
copying bentoml/configuration/default_bentoml.cfg -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/configuration
copying bentoml/deployment/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment
copying bentoml/deployment/operator.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment
copying bentoml/deployment/store.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment
copying bentoml/deployment/utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment
copying bentoml/deployment/aws_lambda/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/aws_lambda
copying bentoml/deployment/aws_lambda/download_extra_resources.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/aws_lambda
copying bentoml/deployment/aws_lambda/lambda_app.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/aws_lambda
copying bentoml/deployment/aws_lambda/utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/aws_lambda
copying bentoml/deployment/sagemaker/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/sagemaker
copying bentoml/deployment/sagemaker/sagemaker_nginx.conf -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/sagemaker
copying bentoml/deployment/sagemaker/sagemaker_serve.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/sagemaker
copying bentoml/deployment/sagemaker/sagemaker_wsgi.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/deployment/sagemaker
copying bentoml/handlers/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/base_handlers.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/clipper_handler.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/dataframe_handler.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/fastai_image_handler.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/image_handler.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/json_handler.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/pytorch_tensor_handler.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/tensorflow_tensor_handler.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/handlers/utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/handlers
copying bentoml/migrations/README -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/migrations
copying bentoml/migrations/env.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/migrations
copying bentoml/migrations/script.py.mako -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/migrations
copying bentoml/migrations/versions/a6b00ae45279_add_last_updated_at_for_deployments.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/migrations/versions
copying bentoml/proto/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/proto
copying bentoml/proto/deployment_pb2.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/proto
copying bentoml/proto/repository_pb2.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/proto
copying bentoml/proto/status_pb2.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/proto
copying bentoml/proto/yatai_service_pb2.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/proto
copying bentoml/proto/yatai_service_pb2_grpc.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/proto
copying bentoml/repository/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/repository
copying bentoml/repository/metadata_store.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/repository
copying bentoml/server/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server
copying bentoml/server/bento_api_server.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server
copying bentoml/server/bento_sagemaker_server.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server
copying bentoml/server/gunicorn_config.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server
copying bentoml/server/gunicorn_server.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server
copying bentoml/server/middlewares.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server
copying bentoml/server/utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server
copying bentoml/server/static/swagger-ui-bundle.js -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server/static
copying bentoml/server/static/swagger-ui.css -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/server/static
copying bentoml/utils/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils
copying bentoml/utils/cloudpickle.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils
copying bentoml/utils/hybirdmethod.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils
copying bentoml/utils/log.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils
copying bentoml/utils/s3.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils
copying bentoml/utils/tempdir.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils
copying bentoml/utils/usage_stats.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils
copying bentoml/utils/validator/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/utils/validator
copying bentoml/yatai/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai
copying bentoml/yatai/deployment_utils.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai
copying bentoml/yatai/status.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai
copying bentoml/yatai/yatai_service_impl.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai
copying bentoml/yatai/client/__init__.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai/client
copying bentoml/yatai/client/bento_repository_api.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai/client
copying bentoml/yatai/client/deployment_api.py -> BentoML-0.6.1+2.gefb0204.dirty/bentoml/yatai/client
Writing BentoML-0.6.1+2.gefb0204.dirty/setup.cfg
UPDATING BentoML-0.6.1+2.gefb0204.dirty/bentoml/_version.py
set BentoML-0.6.1+2.gefb0204.dirty/bentoml/_version.py to '0.6.1+2.gefb0204.dirty'
Creating tar archive
removing 'BentoML-0.6.1+2.gefb0204.dirty' (and everything under it)
[2020-01-29 21:09:46,434] INFO - BentoService bundle 'SKSentimentAnalysis:20200129210903_E48487' created at: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-ibnzwxwb
[2020-01-29 21:09:46,435] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-29 21:09:46,446] WARNING - Saved BentoService bundle version mismatch: loading BentoServie bundle create with BentoML version 0.6.1,  but loading from BentoML version 0.6.1+0.g4b30c1a.dirty
[2020-01-29 21:09:46,832] INFO - BentoService bundle 'SKSentimentAnalysis:20200129210903_E48487' created at: /Users/bozhaoyu/bentoml/repository/SKSentimentAnalysis/20200129210903_E48487

Load BentoService archive from saved path

In [66]:
import bentoml

# Load exported bentoML model archive from path
loaded_bento_service = bentoml.load(saved_path)

# Call predict on the restored sklearn model
loaded_bento_service.predict(pd.Series(["good", "great"]))
[2020-01-29 20:59:11,946] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-29 20:59:11,956] WARNING - Saved BentoService bundle version mismatch: loading BentoServie bundle create with BentoML version 0.6.1,  but loading from BentoML version 0.6.1+0.g4b30c1a.dirty
[2020-01-29 20:59:11,957] WARNING - Module `sentiment_analysis_service` already loaded, using existing imported module.
[2020-01-29 20:59:29,061] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
Out[66]:
array([4, 4])
In [80]:
!bentoml get SKSentimentAnalysis
BENTO_SERVICE                              CREATED_AT        APIS                       ARTIFACTS
SKSentimentAnalysis:20200129210903_E48487  2020-01-30 05:09  predict::DataframeHandler  model::PickleArtifact
SKSentimentAnalysis:20200129205654_0D29B1  2020-01-30 04:57  predict::DataframeHandler  model::SklearnModelArtifact
SKSentimentAnalysis:20200129115524_801942  2020-01-29 19:56  predict::DataframeHandler  model::SklearnModelArtifact
SKSentimentAnalysis:20200128134748_BC079E  2020-01-28 21:48  predict::DataframeHandler  model::SklearnModelArtifact
SKSentimentAnalysis:20200128134526_FCDE3C  2020-01-28 21:45  predict::DataframeHandler  model::SklearnModelArtifact
SKSentimentAnalysis:20200128132708_0E9AD8  2020-01-28 21:28  predict::DataframeHandler  model::SklearnModelArtifact
SKSentimentAnalysis:20200128131725_1A2FD7  2020-01-28 21:18  predict::DataframeHandler  model::SklearnModelArtifact
SKSentimentAnalysis:20200128121823_F1A035  2020-01-28 20:19  predict::DataframeHandler  model::SklearnModelArtifact
SKSentimentAnalysis:20200127144037_AE0EAC  2020-01-27 22:41  predict::DataframeHandler  model::SklearnModelArtifact
In [81]:
!bentoml get SKSentimentAnalysis:20200129205654_0D29B1
{
  "name": "SKSentimentAnalysis",
  "version": "20200129205654_0D29B1",
  "uri": {
    "type": "LOCAL",
    "uri": "/Users/bozhaoyu/bentoml/repository/SKSentimentAnalysis/20200129205654_0D29B1"
  },
  "bentoServiceMetadata": {
    "name": "SKSentimentAnalysis",
    "version": "20200129205654_0D29B1",
    "createdAt": "2020-01-30T04:57:42.457829Z",
    "env": {
      "condaEnv": "name: bentoml-SKSentimentAnalysis\nchannels:\n- defaults\ndependencies:\n- python=3.7.3\n- pip\n",
      "pipDependencies": "bentoml==0.6.1\nscikit-learn\npandas",
      "pythonVersion": "3.7.3"
    },
    "artifacts": [
      {
        "name": "model",
        "artifactType": "SklearnModelArtifact"
      }
    ],
    "apis": [
      {
        "name": "predict",
        "handlerType": "DataframeHandler",
        "docs": "predict expects pandas.Series as input"
      }
    ]
  }
}
In [82]:
!bentoml run SKSentimentAnalysis:20200129205654_0D29B1 predict \
--input '["some new text, sweet noodles", "happy time", "sad day"]'
[2020-01-29 21:26:23,608] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-29 21:26:23,626] WARNING - Saved BentoService bundle version mismatch: loading BentoServie bundle create with BentoML version 0.6.1,  but loading from BentoML version 0.6.1+2.gefb0204.dirty
[2020-01-29 21:26:24,203] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-29 21:26:41,449] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[4 4 0]

Model Serving via REST API

Run REST API server locally

In [36]:
!bentoml serve {saved_path}
[2020-01-28 10:11:44,198] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-28 10:11:44,209] WARNING - Saved BentoService bundle version mismatch: loading BentoServie bundle create with BentoML version 0.6.1,  but loading from BentoML version 0.6.1+1.g2647cf3.dirty
[2020-01-28 10:11:44,551] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
[2020-01-28 10:12:04,950] WARNING - BentoML local changes detected - Local BentoML repository including all code changes will be bundled together with the BentoService bundle. When used with docker, the base docker image will be default to same version as last PyPI release at version: 0.6.1. You can also force bentoml to use a specific version for deploying your BentoService bundle, by setting the config 'core/bentoml_deploy_version' to a pinned version or your custom BentoML on github, e.g.:'bentoml_deploy_version = git+https://github.com/{username}/[email protected]{branch}'
 * Serving Flask app "SKSentimentAnalysis" (lazy loading)
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
^C

Send prediction request to REST API server

Run the following command in terminal to make a HTTP request to the API server:

curl -i \
--header "Content-Type: application/json" \
--request POST \
--data '["some new text, sweet noodles", "happy time", "sad day"]' \
localhost:5000/predict

You can also view all availabl API endpoints at localhost:5000, or look at prometheus metrics at localhost:5000/metrics in browser.

"pip install" a saved BentoService archive

BentoML user can directly pip install saved BentoML archive with pip install {saved_path}, and use it as a regular python package.

In [18]:
!pip install {saved_path}
Processing /Users/bozhaoyu/bentoml/repository/SKSentimentAnalysis/20200127144037_AE0EAC
Requirement already satisfied: bentoml==0.6.1 in /Users/bozhaoyu/src/bento (from SKSentimentAnalysis===20200127144037-AE0EAC) (0.6.1)
Requirement already satisfied: scikit-learn in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from SKSentimentAnalysis===20200127144037-AE0EAC) (0.22)
Requirement already satisfied: pandas in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from SKSentimentAnalysis===20200127144037-AE0EAC) (0.24.2)
Requirement already satisfied: ruamel.yaml>=0.15.0 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.15.99)
Requirement already satisfied: numpy in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.16.4)
Requirement already satisfied: flask in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.0.4)
Requirement already satisfied: gunicorn in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (19.9.0)
Requirement already satisfied: click>=7.0 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (7.0)
Requirement already satisfied: prometheus_client in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.7.1)
Requirement already satisfied: python-json-logger in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.1.11)
Requirement already satisfied: boto3 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.10.42)
Requirement already satisfied: requests in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (2.22.0)
Requirement already satisfied: packaging in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (19.0)
Requirement already satisfied: docker in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (4.1.0)
Requirement already satisfied: configparser in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (3.7.4)
Requirement already satisfied: sqlalchemy>=1.3.0 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.3.6)
Requirement already satisfied: protobuf>=3.6.0 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (3.7.0)
Requirement already satisfied: grpcio in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.22.0)
Requirement already satisfied: cerberus in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.3.1)
Requirement already satisfied: tabulate in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.8.3)
Requirement already satisfied: humanfriendly in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (4.18)
Requirement already satisfied: alembic in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.2.1)
Requirement already satisfied: python-dateutil<2.8.1,>=2.1 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (2.8.0)
Requirement already satisfied: joblib>=0.11 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from scikit-learn->SKSentimentAnalysis===20200127144037-AE0EAC) (0.14.1)
Requirement already satisfied: scipy>=0.17.0 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from scikit-learn->SKSentimentAnalysis===20200127144037-AE0EAC) (1.2.1)
Requirement already satisfied: pytz>=2011k in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from pandas->SKSentimentAnalysis===20200127144037-AE0EAC) (2019.1)
Requirement already satisfied: itsdangerous>=0.24 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from flask->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.1.0)
Requirement already satisfied: Werkzeug>=0.14 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from flask->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.15.4)
Requirement already satisfied: Jinja2>=2.10 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from flask->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (2.10.1)
Requirement already satisfied: botocore<1.14.0,>=1.13.42 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from boto3->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.13.42)
Requirement already satisfied: s3transfer<0.3.0,>=0.2.0 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from boto3->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.2.1)
Requirement already satisfied: jmespath<1.0.0,>=0.7.1 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from boto3->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.9.4)
Requirement already satisfied: certifi>=2017.4.17 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from requests->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (2019.11.28)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from requests->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.24.1)
Requirement already satisfied: idna<2.9,>=2.5 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from requests->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from requests->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (3.0.4)
Requirement already satisfied: six in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from packaging->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.14.0)
Requirement already satisfied: pyparsing>=2.0.2 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from packaging->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (2.4.0)
Requirement already satisfied: websocket-client>=0.32.0 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from docker->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.57.0)
Requirement already satisfied: setuptools in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from protobuf>=3.6.0->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (45.1.0.post20200119)
Requirement already satisfied: python-editor>=0.3 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from alembic->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.0.4)
Requirement already satisfied: Mako in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from alembic->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.1.0)
Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from Jinja2>=2.10->flask->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (1.1.1)
Requirement already satisfied: docutils<0.16,>=0.10 in /usr/local/anaconda3/envs/dev-py3/lib/python3.7/site-packages (from botocore<1.14.0,>=1.13.42->boto3->bentoml==0.6.1->SKSentimentAnalysis===20200127144037-AE0EAC) (0.15.2)
Building wheels for collected packages: SKSentimentAnalysis
  Building wheel for SKSentimentAnalysis (setup.py) ... done
  Created wheel for SKSentimentAnalysis: filename=SKSentimentAnalysis-20200127144037_AE0EAC-py3-none-any.whl size=57940664 sha256=7a7dbda641507991ac49b8bb404ffc868f404b06fde29f942d564986fe531ec0
  Stored in directory: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/pip-ephem-wheel-cache-wg_ahs5y/wheels/17/30/b7/8fb7d7f796f86f6c25b988c47cf5173f3be837cace665d0ced
Successfully built SKSentimentAnalysis
Installing collected packages: SKSentimentAnalysis
Successfully installed SKSentimentAnalysis-20200127144037-AE0EAC
In [20]:
# Your bentoML model class name will become packaged name
import SKSentimentAnalysis

svc = SKSentimentAnalysis.load() # call load to ensure all artifacts are loaded
svc.predict(pd.Series(["bad", "awesome"]))
Out[20]:
array([0, 4])

PyPI package Command Line Access

pip install saved_path also installs a CLI tool for accessing the BentoML service

In [22]:
!SKSentimentAnalysis info
{
  "name": "SKSentimentAnalysis",
  "version": "20200127144037_AE0EAC",
  "created_at": "2020-01-27T22:41:25.663929Z",
  "env": {
    "conda_env": "name: bentoml-SKSentimentAnalysis\nchannels:\n- defaults\ndependencies:\n- python=3.7.3\n- pip\n",
    "pip_dependencies": "bentoml==0.6.1\nscikit-learn\npandas",
    "python_version": "3.7.3"
  },
  "artifacts": [
    {
      "name": "model",
      "artifact_type": "SklearnModelArtifact"
    }
  ],
  "apis": [
    {
      "name": "predict",
      "handler_type": "DataframeHandler",
      "docs": "predict expects pandas.Series as input"
    }
  ]
}
In [23]:
!SKSentimentAnalysis --help
Usage: SKSentimentAnalysis [OPTIONS] COMMAND [ARGS]...

  BentoML CLI tool

Options:
  --version  Show the version and exit.
  --help     Show this message and exit.

Commands:
  info            List APIs
  open-api-spec   Display OpenAPI/Swagger JSON specs
  run             Run API function
  serve           Start local rest server
  serve-gunicorn  Start local gunicorn server
In [24]:
# Run prediction with sample input
!SKSentimentAnalysis run predict --input='["some new text, sweet noodles", "happy time", "sad day"]'
[4 4 0]
In [25]:
# OpenAPI docs for generating API Client
!SKSentimentAnalysis open-api-spec
{
  "openapi": "3.0.0",
  "info": {
    "version": "20200127144037_AE0EAC",
    "title": "SKSentimentAnalysis",
    "description": "To get a client SDK, copy all content from <a href=\"/docs.json\">docs</a> and paste into <a href=\"https://editor.swagger.io\">editor.swagger.io</a> then click the tab <strong>Generate Client</strong> and choose the language."
  },
  "tags": [
    {
      "name": "infra"
    },
    {
      "name": "app"
    }
  ],
  "paths": {
    "/healthz": {
      "get": {
        "tags": [
          "infra"
        ],
        "description": "Health check endpoint. Expecting an empty response with status code 200 when the service is in health state",
        "responses": {
          "200": {
            "description": "success"
          }
        }
      }
    },
    "/metrics": {
      "get": {
        "tags": [
          "infra"
        ],
        "description": "Prometheus metrics endpoint",
        "responses": {
          "200": {
            "description": "success"
          }
        }
      }
    },
    "/feedback": {
      "get": {
        "tags": [
          "infra"
        ],
        "description": "Predictions feedback endpoint. Expecting feedback request in JSON format and must contain a `request_id` field, which can be obtained from any BentoService API response header",
        "responses": {
          "200": {
            "description": "success"
          }
        }
      },
      "post": {
        "tags": [
          "infra"
        ],
        "description": "Predictions feedback endpoint. Expecting feedback request in JSON format and must contain a `request_id` field, which can be obtained from any BentoService API response header",
        "responses": {
          "200": {
            "description": "success"
          }
        }
      }
    },
    "/predict": {
      "post": {
        "tags": [
          "app"
        ],
        "description": "predict expects pandas.Series as input",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "success"
          }
        }
      }
    }
  }
}

Run REST API server with Docker

** Note: docker is not available when running in Google Colaboratory

1) build docker image with saved Bento and tag it (e.g. sentiment-analysis-servicel)

In [31]:
!cd {saved_path} && docker build -t sk-sentiment-analysis .
Sending build context to Docker daemon  123.4MB
Step 1/12 : FROM continuumio/miniconda3:4.7.12
 ---> 406f2b43ea59
Step 2/12 : ENTRYPOINT [ "/bin/bash", "-c" ]
 ---> Using cache
 ---> 28172be83c07
Step 3/12 : EXPOSE 5000
 ---> Using cache
 ---> 840844d191d4
Step 4/12 : RUN set -x      && apt-get update      && apt-get install --no-install-recommends --no-install-suggests -y libpq-dev build-essential      && rm -rf /var/lib/apt/lists/*
 ---> Using cache
 ---> 243c05e712f3
Step 5/12 : RUN conda install pip numpy scipy       && pip install gunicorn
 ---> Using cache
 ---> 8fab95ab34fc
Step 6/12 : COPY . /bento
 ---> 67d9e50d566b
Step 7/12 : WORKDIR /bento
 ---> Running in b3dcad063ce1
Removing intermediate container b3dcad063ce1
 ---> f14962580e56
Step 8/12 : RUN if [ -f /bento/setup.sh ]; then /bin/bash -c /bento/setup.sh; fi
 ---> Running in 93e35cb1765b
Removing intermediate container 93e35cb1765b
 ---> b274d4877198
Step 9/12 : RUN conda env update -n base -f /bento/environment.yml
 ---> Running in 2ecba597d9d5
Collecting package metadata (repodata.json): ...working... done
Solving environment: ...working... done

Downloading and Extracting Packages
pip-20.0.2           | 1.7 MB    | ########## | 100% 
python-3.7.3         | 32.1 MB   | ########## | 100% 
Preparing transaction: ...working... done
Verifying transaction: ...working... done
Executing transaction: ...working... done
#
# To activate this environment, use
#
#     $ conda activate base
#
# To deactivate an active environment, use
#
#     $ conda deactivate

Removing intermediate container 2ecba597d9d5
 ---> cfebc200ccb1
Step 10/12 : RUN pip install -r /bento/requirements.txt
 ---> Running in 9518c92df6f6
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Collecting bentoml==0.6.1
  Downloading BentoML-0.6.1-py3-none-any.whl (553 kB)
Collecting scikit-learn
  Downloading scikit_learn-0.22.1-cp37-cp37m-manylinux1_x86_64.whl (7.0 MB)
Collecting pandas
  Downloading pandas-0.25.3-cp37-cp37m-manylinux1_x86_64.whl (10.4 MB)
Requirement already satisfied: numpy in /opt/conda/lib/python3.7/site-packages (from bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (1.18.1)
Collecting ruamel.yaml>=0.15.0
  Downloading ruamel.yaml-0.16.6-py2.py3-none-any.whl (123 kB)
Collecting protobuf>=3.6.0
  Downloading protobuf-3.11.2-cp37-cp37m-manylinux1_x86_64.whl (1.3 MB)
Requirement already satisfied: gunicorn in /opt/conda/lib/python3.7/site-packages (from bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (20.0.4)
Collecting alembic
  Downloading alembic-1.3.3.tar.gz (1.1 MB)
Requirement already satisfied: requests in /opt/conda/lib/python3.7/site-packages (from bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (2.22.0)
Collecting docker
  Downloading docker-4.1.0-py2.py3-none-any.whl (139 kB)
Collecting python-json-logger
  Downloading python-json-logger-0.1.11.tar.gz (6.0 kB)
Collecting prometheus-client
  Downloading prometheus_client-0.7.1.tar.gz (38 kB)
Collecting flask
  Downloading Flask-1.1.1-py2.py3-none-any.whl (94 kB)
Collecting humanfriendly
  Downloading humanfriendly-4.18-py2.py3-none-any.whl (73 kB)
Collecting python-dateutil<2.8.1,>=2.1
  Downloading python_dateutil-2.8.0-py2.py3-none-any.whl (226 kB)
Collecting packaging
  Downloading packaging-20.1-py2.py3-none-any.whl (36 kB)
Collecting cerberus
  Downloading Cerberus-1.3.2.tar.gz (52 kB)
Collecting boto3
  Downloading boto3-1.11.9-py2.py3-none-any.whl (128 kB)
Collecting configparser
  Downloading configparser-4.0.2-py2.py3-none-any.whl (22 kB)
Collecting tabulate
  Downloading tabulate-0.8.6.tar.gz (45 kB)
Collecting grpcio
  Downloading grpcio-1.26.0-cp37-cp37m-manylinux2010_x86_64.whl (2.4 MB)
Collecting click>=7.0
  Downloading Click-7.0-py2.py3-none-any.whl (81 kB)
Collecting sqlalchemy>=1.3.0
  Downloading SQLAlchemy-1.3.13.tar.gz (6.0 MB)
Requirement already satisfied: scipy>=0.17.0 in /opt/conda/lib/python3.7/site-packages (from scikit-learn->-r /bento/requirements.txt (line 2)) (1.3.2)
Collecting joblib>=0.11
  Downloading joblib-0.14.1-py2.py3-none-any.whl (294 kB)
Collecting pytz>=2017.2
  Downloading pytz-2019.3-py2.py3-none-any.whl (509 kB)
Collecting ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and python_version < "3.8"
  Downloading ruamel.yaml.clib-0.2.0-cp37-cp37m-manylinux1_x86_64.whl (547 kB)
Requirement already satisfied: setuptools in /opt/conda/lib/python3.7/site-packages (from protobuf>=3.6.0->bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (41.4.0)
Requirement already satisfied: six>=1.9 in /opt/conda/lib/python3.7/site-packages (from protobuf>=3.6.0->bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (1.12.0)
Collecting Mako
  Downloading Mako-1.1.1.tar.gz (468 kB)
Collecting python-editor>=0.3
  Downloading python_editor-1.0.4-py3-none-any.whl (4.9 kB)
Requirement already satisfied: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (2019.11.28)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (1.24.2)
Requirement already satisfied: idna<2.9,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (2.8)
Requirement already satisfied: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->bentoml==0.6.1->-r /bento/requirements.txt (line 1)) (3.0.4)
Collecting websocket-client>=0.32.0
  Downloading websocket_client-0.57.0-py2.py3-none-any.whl (200 kB)
Collecting Jinja2>=2.10.1
  Downloading Jinja2-2.11.0-py2.py3-none-any.whl (126 kB)
Collecting itsdangerous>=0.24
  Downloading itsdangerous-1.1.0-py2.py3-none-any.whl (16 kB)
Collecting Werkzeug>=0.15
  Downloading Werkzeug-0.16.1-py2.py3-none-any.whl (327 kB)
Collecting pyparsing>=2.0.2
  Downloading pyparsing-2.4.6-py2.py3-none-any.whl (67 kB)
Collecting jmespath<1.0.0,>=0.7.1
  Downloading jmespath-0.9.4-py2.py3-none-any.whl (24 kB)
Collecting s3transfer<0.4.0,>=0.3.0
  Downloading s3transfer-0.3.2-py2.py3-none-any.whl (69 kB)
Collecting botocore<1.15.0,>=1.14.9
  Downloading botocore-1.14.9-py2.py3-none-any.whl (5.9 MB)
Collecting MarkupSafe>=0.9.2
  Downloading MarkupSafe-1.1.1-cp37-cp37m-manylinux1_x86_64.whl (27 kB)
Collecting docutils<0.16,>=0.10
  Downloading docutils-0.15.2-py3-none-any.whl (547 kB)
Building wheels for collected packages: alembic, python-json-logger, prometheus-client, cerberus, tabulate, sqlalchemy, Mako
  Building wheel for alembic (setup.py): started
  Building wheel for alembic (setup.py): finished with status 'done'
  Created wheel for alembic: filename=alembic-1.3.3-py2.py3-none-any.whl size=155684 sha256=3167806ac6b0296dc1735b8db3d939d5e979caf1217b723341dd8c88aa6259f1
  Stored in directory: /root/.cache/pip/wheels/71/63/41/f20802c61cc6cf93b6d71ff017970ae2d3a79f7d143627a0f1
  Building wheel for python-json-logger (setup.py): started
  Building wheel for python-json-logger (setup.py): finished with status 'done'
  Created wheel for python-json-logger: filename=python_json_logger-0.1.11-py2.py3-none-any.whl size=5076 sha256=9e68a1af7f989755feec41015eed7365d23fcb792e02f4b8f075ec7e4799ed1f
  Stored in directory: /root/.cache/pip/wheels/fa/7f/fd/92ccdbb9d1a65486406e0363d2ba5b4ce52f400a915f602ecb
  Building wheel for prometheus-client (setup.py): started
  Building wheel for prometheus-client (setup.py): finished with status 'done'
  Created wheel for prometheus-client: filename=prometheus_client-0.7.1-py3-none-any.whl size=41402 sha256=5d83f05f97a3c7353efcaf51968d6c09d25d71342583c992356d1569d6494ea3
  Stored in directory: /root/.cache/pip/wheels/30/0c/26/59ba285bf65dc79d195e9b25e2ddde4c61070422729b0cd914
  Building wheel for cerberus (setup.py): started
  Building wheel for cerberus (setup.py): finished with status 'done'
  Created wheel for cerberus: filename=Cerberus-1.3.2-py3-none-any.whl size=54335 sha256=c089498419684e5e81d4550bbb303abfae56940a60c1dc7cd4aa2b1797980e07
  Stored in directory: /root/.cache/pip/wheels/17/3a/0d/e2fc48cf85cb858f5e65f1baa36180ebb5dce6397c35c4cfcb
  Building wheel for tabulate (setup.py): started
  Building wheel for tabulate (setup.py): finished with status 'done'
  Created wheel for tabulate: filename=tabulate-0.8.6-py3-none-any.whl size=23273 sha256=1e2ac06f60ddd211e05f0f23937233a0f1e6d42ff7d553069f710098fd730b50
  Stored in directory: /root/.cache/pip/wheels/09/b6/7e/08b4ee715a1239453e89a59081f0ac369a9036f232e013ecd8
  Building wheel for sqlalchemy (setup.py): started
  Building wheel for sqlalchemy (setup.py): finished with status 'done'
  Created wheel for sqlalchemy: filename=SQLAlchemy-1.3.13-cp37-cp37m-linux_x86_64.whl size=1223709 sha256=a3589c89331982830cf1bba0187eec69217d2be87bebdda137be736aca59b877
  Stored in directory: /root/.cache/pip/wheels/b9/ba/77/163f10f14bd489351530603e750c195b0ceceed2f3be2b32f1
  Building wheel for Mako (setup.py): started
  Building wheel for Mako (setup.py): finished with status 'done'
  Created wheel for Mako: filename=Mako-1.1.1-py3-none-any.whl size=75409 sha256=ac1c12f7fb3cd5c184dd788db6805a3a09b890477305c63b50a5bc0ac162fe36
  Stored in directory: /root/.cache/pip/wheels/11/fe/fa/3693b62cf5ec2b2784b6496734f0ee3e2321eb66d66607e5f9
Successfully built alembic python-json-logger prometheus-client cerberus tabulate sqlalchemy Mako
Installing collected packages: ruamel.yaml.clib, ruamel.yaml, protobuf, sqlalchemy, MarkupSafe, Mako, python-editor, python-dateutil, alembic, websocket-client, docker, python-json-logger, prometheus-client, Jinja2, itsdangerous, Werkzeug, click, flask, humanfriendly, pyparsing, packaging, cerberus, jmespath, docutils, botocore, s3transfer, boto3, configparser, tabulate, pytz, pandas, grpcio, bentoml, joblib, scikit-learn
Successfully installed Jinja2-2.11.0 Mako-1.1.1 MarkupSafe-1.1.1 Werkzeug-0.16.1 alembic-1.3.3 bentoml-0.6.1 boto3-1.11.9 botocore-1.14.9 cerberus-1.3.2 click-7.0 configparser-4.0.2 docker-4.1.0 docutils-0.15.2 flask-1.1.1 grpcio-1.26.0 humanfriendly-4.18 itsdangerous-1.1.0 jmespath-0.9.4 joblib-0.14.1 packaging-20.1 pandas-0.25.3 prometheus-client-0.7.1 protobuf-3.11.2 pyparsing-2.4.6 python-dateutil-2.8.0 python-editor-1.0.4 python-json-logger-0.1.11 pytz-2019.3 ruamel.yaml-0.16.6 ruamel.yaml.clib-0.2.0 s3transfer-0.3.2 scikit-learn-0.22.1 sqlalchemy-1.3.13 tabulate-0.8.6 websocket-client-0.57.0
Removing intermediate container 9518c92df6f6
 ---> 30f398610491
Step 11/12 : RUN if [ -f /bento/bentoml_init.sh ]; then /bin/bash -c /bento/bentoml_init.sh; fi
 ---> Running in 26fac21e185c
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
Processing ./bundled_pip_dependencies/BentoML-0.6.1.tar.gz
  Installing build dependencies: started
  Installing build dependencies: finished with status 'done'
  Getting requirements to build wheel: started
  Getting requirements to build wheel: finished with status 'done'
    Preparing wheel metadata: started
    Preparing wheel metadata: finished with status 'done'
Requirement already satisfied, skipping upgrade: python-dateutil<2.8.1,>=2.1 in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (2.8.0)
Requirement already satisfied, skipping upgrade: humanfriendly in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (4.18)
Requirement already satisfied, skipping upgrade: docker in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (4.1.0)
Requirement already satisfied, skipping upgrade: gunicorn in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (20.0.4)
Requirement already satisfied, skipping upgrade: configparser in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (4.0.2)
Requirement already satisfied, skipping upgrade: pandas in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (0.25.3)
Requirement already satisfied, skipping upgrade: tabulate in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (0.8.6)
Requirement already satisfied, skipping upgrade: protobuf>=3.6.0 in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (3.11.2)
Requirement already satisfied, skipping upgrade: requests in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (2.22.0)
Requirement already satisfied, skipping upgrade: flask in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (1.1.1)
Requirement already satisfied, skipping upgrade: ruamel.yaml>=0.15.0 in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (0.16.6)
Requirement already satisfied, skipping upgrade: python-json-logger in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (0.1.11)
Requirement already satisfied, skipping upgrade: prometheus-client in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (0.7.1)
Requirement already satisfied, skipping upgrade: grpcio in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (1.26.0)
Requirement already satisfied, skipping upgrade: cerberus in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (1.3.2)
Requirement already satisfied, skipping upgrade: click>=7.0 in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (7.0)
Requirement already satisfied, skipping upgrade: sqlalchemy>=1.3.0 in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (1.3.13)
Requirement already satisfied, skipping upgrade: alembic in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (1.3.3)
Requirement already satisfied, skipping upgrade: numpy in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (1.18.1)
Requirement already satisfied, skipping upgrade: packaging in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (20.1)
Requirement already satisfied, skipping upgrade: boto3 in /opt/conda/lib/python3.7/site-packages (from BentoML==0.6.1) (1.11.9)
Requirement already satisfied, skipping upgrade: six>=1.5 in /opt/conda/lib/python3.7/site-packages (from python-dateutil<2.8.1,>=2.1->BentoML==0.6.1) (1.12.0)
Requirement already satisfied, skipping upgrade: websocket-client>=0.32.0 in /opt/conda/lib/python3.7/site-packages (from docker->BentoML==0.6.1) (0.57.0)
Requirement already satisfied, skipping upgrade: setuptools>=3.0 in /opt/conda/lib/python3.7/site-packages (from gunicorn->BentoML==0.6.1) (41.4.0)
Requirement already satisfied, skipping upgrade: pytz>=2017.2 in /opt/conda/lib/python3.7/site-packages (from pandas->BentoML==0.6.1) (2019.3)
Requirement already satisfied, skipping upgrade: certifi>=2017.4.17 in /opt/conda/lib/python3.7/site-packages (from requests->BentoML==0.6.1) (2019.11.28)
Requirement already satisfied, skipping upgrade: chardet<3.1.0,>=3.0.2 in /opt/conda/lib/python3.7/site-packages (from requests->BentoML==0.6.1) (3.0.4)
Requirement already satisfied, skipping upgrade: idna<2.9,>=2.5 in /opt/conda/lib/python3.7/site-packages (from requests->BentoML==0.6.1) (2.8)
Requirement already satisfied, skipping upgrade: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /opt/conda/lib/python3.7/site-packages (from requests->BentoML==0.6.1) (1.24.2)
Requirement already satisfied, skipping upgrade: Werkzeug>=0.15 in /opt/conda/lib/python3.7/site-packages (from flask->BentoML==0.6.1) (0.16.1)
Requirement already satisfied, skipping upgrade: Jinja2>=2.10.1 in /opt/conda/lib/python3.7/site-packages (from flask->BentoML==0.6.1) (2.11.0)
Requirement already satisfied, skipping upgrade: itsdangerous>=0.24 in /opt/conda/lib/python3.7/site-packages (from flask->BentoML==0.6.1) (1.1.0)
Requirement already satisfied, skipping upgrade: ruamel.yaml.clib>=0.1.2; platform_python_implementation == "CPython" and python_version < "3.8" in /opt/conda/lib/python3.7/site-packages (from ruamel.yaml>=0.15.0->BentoML==0.6.1) (0.2.0)
Requirement already satisfied, skipping upgrade: python-editor>=0.3 in /opt/conda/lib/python3.7/site-packages (from alembic->BentoML==0.6.1) (1.0.4)
Requirement already satisfied, skipping upgrade: Mako in /opt/conda/lib/python3.7/site-packages (from alembic->BentoML==0.6.1) (1.1.1)
Requirement already satisfied, skipping upgrade: pyparsing>=2.0.2 in /opt/conda/lib/python3.7/site-packages (from packaging->BentoML==0.6.1) (2.4.6)
Requirement already satisfied, skipping upgrade: jmespath<1.0.0,>=0.7.1 in /opt/conda/lib/python3.7/site-packages (from boto3->BentoML==0.6.1) (0.9.4)
Requirement already satisfied, skipping upgrade: s3transfer<0.4.0,>=0.3.0 in /opt/conda/lib/python3.7/site-packages (from boto3->BentoML==0.6.1) (0.3.2)
Requirement already satisfied, skipping upgrade: botocore<1.15.0,>=1.14.9 in /opt/conda/lib/python3.7/site-packages (from boto3->BentoML==0.6.1) (1.14.9)
Requirement already satisfied, skipping upgrade: MarkupSafe>=0.23 in /opt/conda/lib/python3.7/site-packages (from Jinja2>=2.10.1->flask->BentoML==0.6.1) (1.1.1)
Requirement already satisfied, skipping upgrade: docutils<0.16,>=0.10 in /opt/conda/lib/python3.7/site-packages (from botocore<1.15.0,>=1.14.9->boto3->BentoML==0.6.1) (0.15.2)
Building wheels for collected packages: BentoML
  Building wheel for BentoML (PEP 517): started
  Building wheel for BentoML (PEP 517): finished with status 'done'
  Created wheel for BentoML: filename=BentoML-0.6.1-py3-none-any.whl size=505667 sha256=c1f6b20b28250256f356e879575619a1171470fb1727f3b3635238ed322cd6fd
  Stored in directory: /root/.cache/pip/wheels/a2/b5/f6/4b37cd2a90c23d57718be64cb02a49396cc1f8014ebe1612b2
Successfully built BentoML
Installing collected packages: BentoML
  Attempting uninstall: BentoML
    Found existing installation: BentoML 0.6.1
    Uninstalling BentoML-0.6.1:
      Successfully uninstalled BentoML-0.6.1
Successfully installed BentoML-0.6.1
Removing intermediate container 26fac21e185c
 ---> 08ce88940dae
Step 12/12 : CMD ["bentoml serve-gunicorn /bento"]
 ---> Running in 509e19e67e04
Removing intermediate container 509e19e67e04
 ---> 1597af914b10
Successfully built 1597af914b10
Successfully tagged sk-sentiment-analysis:latest

2) run docker image and expose port 5000

In [32]:
!docker run -p 5000:5000 sk-sentiment-analysis
[2020-01-28 00:12:41,498] INFO - get_gunicorn_num_of_workers: 3, calculated by cpu count
[2020-01-28 00:12:41 +0000] [1] [INFO] Starting gunicorn 20.0.4
[2020-01-28 00:12:41 +0000] [1] [INFO] Listening at: http://0.0.0.0:5000 (1)
[2020-01-28 00:12:41 +0000] [1] [INFO] Using worker: sync
[2020-01-28 00:12:41 +0000] [9] [INFO] Booting worker with pid: 9
[2020-01-28 00:12:41 +0000] [10] [INFO] Booting worker with pid: 10
[2020-01-28 00:12:41 +0000] [11] [INFO] Booting worker with pid: 11
^C
[2020-01-28 00:12:53 +0000] [1] [INFO] Handling signal: int

3) Similarly use the following command to query the REST server in Docker

curl -i \
--header "Content-Type: application/json" \
--request POST \
--data '["some new text, sweet noodles", "happy time", "sad day"]' \
localhost:5000/predict

Deploy BentoService as REST API server to the cloud

BentoML support deployment to multiply cloud provider services, such as AWS Lambda, AWS Sagemaker, Google Cloudrun and etc. You can find the full list and guide on the documentation site at https://docs.bentoml.org/en/latest/deployment/index.html

For this demo, we are going to deploy to AWS Lambda

Deploying to Lambda with single command bentoml lambda deploy

In [78]:
!bentoml lambda deploy first-sk-sentiment -b SKSentimentAnalysis:20200129210903_E48487 \
--api-name predict --verbose
[2020-01-29 21:13:45,457] DEBUG - Using BentoML with local Yatai server
[2020-01-29 21:13:45,542] DEBUG - Upgrading tables to the latest revision
Deploying Lambda deployment |[2020-01-29 21:13:46,648] DEBUG - Creating s3 bucket: btml-bobo-first-sk-sentiment-544c24 in region us-west-2
/[2020-01-29 21:13:47,330] DEBUG - Created temporary directory: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze
[2020-01-29 21:13:47,330] DEBUG - Generating cloudformation template.yaml for lambda project at /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze
[2020-01-29 21:13:47,338] DEBUG - Validating generated template.yaml
[2020-01-29 21:13:47,338] DEBUG - Setting envar "AWS_DEFAULT_REGION" to us-west-2 for subprocess call
|[2020-01-29 21:13:50,729] DEBUG - SAM cmd ['sam', 'validate', '--template-file', '/private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/template.yaml', '--region', 'us-west-2'] output: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/template.yaml is a valid SAM Template

[2020-01-29 21:13:50,730] DEBUG - Initializing lambda project in directory: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze ...
[2020-01-29 21:13:50,730] DEBUG - Coping requirements.txt
[2020-01-29 21:13:50,731] DEBUG - Coping bundled_dependencies
[2020-01-29 21:13:50,734] DEBUG - Updating requirements.txt
[2020-01-29 21:13:50,734] DEBUG - Coping model directory
-[2020-01-29 21:13:50,981] DEBUG - Creating python files for lambda function
[2020-01-29 21:13:50,982] INFO - Building lambda project
[2020-01-29 21:13:50,982] DEBUG - Setting envar "AWS_DEFAULT_REGION" to us-west-2 for subprocess call
/[2020-01-29 21:16:08,195] DEBUG - SAM cmd ['sam', 'build', '--use-container', '--region', 'us-west-2'] output: 
Build Succeeded

Built Artifacts  : .aws-sam/build
Built Template   : .aws-sam/build/template.yaml

Commands you can use next
=========================
[*] Invoke Function: sam local invoke
[*] Deploy: sam deploy --guided
    

[2020-01-29 21:16:08,196] DEBUG - Removing unnecessary files to free up space
[2020-01-29 21:16:08,197] DEBUG - Cleaning up unused files in SAM built directory /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict
[2020-01-29 21:16:08,198] DEBUG - removing dir: pyparsing-2.4.6.dist-info
[2020-01-29 21:16:08,199] DEBUG - removing dir: gunicorn-20.0.4.dist-info
[2020-01-29 21:16:08,200] DEBUG - removing dir: botocore-1.14.9.dist-info
[2020-01-29 21:16:08,201] DEBUG - removing dir: humanfriendly-4.18.dist-info
[2020-01-29 21:16:08,202] DEBUG - removing dir: chardet-3.0.4.dist-info
[2020-01-29 21:16:08,204] DEBUG - removing dir: Mako-1.1.1.dist-info
[2020-01-29 21:16:08,206] DEBUG - removing dir: Werkzeug-0.16.1.dist-info
[2020-01-29 21:16:08,208] DEBUG - removing dir: itsdangerous-1.1.0.dist-info
[2020-01-29 21:16:08,209] DEBUG - removing dir: websocket_client-0.57.0.dist-info
[2020-01-29 21:16:08,210] DEBUG - removing dir: joblib-0.14.1.dist-info
[2020-01-29 21:16:08,211] DEBUG - removing dir: BentoML-0.6.1+2.gefb0204.dirty.dist-info
[2020-01-29 21:16:08,212] DEBUG - removing dir: scikit_learn-0.22.1.dist-info
[2020-01-29 21:16:08,213] DEBUG - removing dir: boto3-1.11.9.dist-info
[2020-01-29 21:16:08,214] DEBUG - removing dir: configparser-4.0.2.dist-info
[2020-01-29 21:16:08,215] DEBUG - removing dir: grpcio-1.26.0.dist-info
[2020-01-29 21:16:08,216] DEBUG - removing dir: Click-7.0.dist-info
[2020-01-29 21:16:08,217] DEBUG - removing dir: Flask-1.1.1.dist-info
[2020-01-29 21:16:08,218] DEBUG - removing dir: MarkupSafe-1.1.1.dist-info
[2020-01-29 21:16:08,219] DEBUG - removing dir: protobuf-3.11.2.dist-info
[2020-01-29 21:16:08,220] DEBUG - removing dir: tabulate-0.8.6.dist-info
[2020-01-29 21:16:08,221] DEBUG - removing dir: prometheus_client-0.7.1.dist-info
[2020-01-29 21:16:08,222] DEBUG - removing dir: alembic-1.3.3.dist-info
[2020-01-29 21:16:08,223] DEBUG - removing dir: ruamel.yaml-0.16.6.dist-info
[2020-01-29 21:16:08,224] DEBUG - removing dir: setuptools-45.1.0.dist-info
[2020-01-29 21:16:08,225] DEBUG - removing dir: pytz-2019.3.dist-info
[2020-01-29 21:16:08,226] DEBUG - removing dir: six-1.14.0.dist-info
[2020-01-29 21:16:08,227] DEBUG - removing dir: urllib3-1.25.8.dist-info
[2020-01-29 21:16:08,228] DEBUG - removing dir: s3transfer-0.3.2.dist-info
[2020-01-29 21:16:08,229] DEBUG - removing dir: docutils-0.15.2.dist-info
[2020-01-29 21:16:08,230] DEBUG - removing dir: idna-2.8.dist-info
[2020-01-29 21:16:08,231] DEBUG - removing dir: certifi-2019.11.28.dist-info
[2020-01-29 21:16:08,232] DEBUG - removing dir: jmespath-0.9.4.dist-info
[2020-01-29 21:16:08,233] DEBUG - removing dir: pandas-0.25.3.dist-info
[2020-01-29 21:16:08,234] DEBUG - removing dir: python_dateutil-2.8.0.dist-info
[2020-01-29 21:16:08,236] DEBUG - removing dir: scipy-1.4.1.dist-info
[2020-01-29 21:16:08,237] DEBUG - removing dir: numpy-1.18.1.dist-info
[2020-01-29 21:16:08,238] DEBUG - removing dir: Jinja2-2.11.0.dist-info
[2020-01-29 21:16:08,238] DEBUG - removing dir: SQLAlchemy-1.3.13.dist-info
[2020-01-29 21:16:08,239] DEBUG - removing dir: python_editor-1.0.4.dist-info
[2020-01-29 21:16:08,240] DEBUG - removing dir: python_json_logger-0.1.11.dist-info
[2020-01-29 21:16:08,241] DEBUG - removing dir: ruamel.yaml.clib-0.2.0.dist-info
[2020-01-29 21:16:08,242] DEBUG - removing dir: requests-2.22.0.dist-info
[2020-01-29 21:16:08,243] DEBUG - removing dir: packaging-20.1.dist-info
[2020-01-29 21:16:08,244] DEBUG - removing dir: Cerberus-1.3.2.dist-info
[2020-01-29 21:16:08,245] DEBUG - removing dir: docker-4.1.0.dist-info
[2020-01-29 21:16:08,247] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/websocket/tests
[2020-01-29 21:16:08,262] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/tests
[2020-01-29 21:16:08,263] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/distutils/tests
[2020-01-29 21:16:08,265] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/compat/tests
[2020-01-29 21:16:08,266] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/core/tests
|[2020-01-29 21:16:08,271] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/linalg/tests
[2020-01-29 21:16:08,272] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/ma/tests
[2020-01-29 21:16:08,273] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/f2py/tests
[2020-01-29 21:16:08,278] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/testing/tests
[2020-01-29 21:16:08,279] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/lib/tests
[2020-01-29 21:16:08,282] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/fft/tests
[2020-01-29 21:16:08,282] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/random/tests
[2020-01-29 21:16:08,285] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/matrixlib/tests
[2020-01-29 21:16:08,287] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/numpy/polynomial/tests
[2020-01-29 21:16:08,315] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/tests
[2020-01-29 21:16:08,317] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/tree/tests
[2020-01-29 21:16:08,318] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/metrics/tests
[2020-01-29 21:16:08,319] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/metrics/cluster/tests
[2020-01-29 21:16:08,320] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/metrics/_plot/tests
[2020-01-29 21:16:08,321] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/ensemble/tests
[2020-01-29 21:16:08,322] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/ensemble/_hist_gradient_boosting/tests
[2020-01-29 21:16:08,324] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/experimental/tests
[2020-01-29 21:16:08,324] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/cluster/tests
[2020-01-29 21:16:08,326] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/feature_extraction/tests
[2020-01-29 21:16:08,327] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/semi_supervised/tests
[2020-01-29 21:16:08,327] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/gaussian_process/tests
[2020-01-29 21:16:08,328] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/compose/tests
[2020-01-29 21:16:08,328] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/datasets/tests
[2020-01-29 21:16:08,338] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/linear_model/tests
[2020-01-29 21:16:08,340] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/impute/tests
[2020-01-29 21:16:08,341] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/utils/tests
[2020-01-29 21:16:08,344] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/covariance/tests
[2020-01-29 21:16:08,345] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/neural_network/tests
[2020-01-29 21:16:08,346] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/feature_selection/tests
[2020-01-29 21:16:08,347] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/inspection/tests
[2020-01-29 21:16:08,347] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/svm/tests
[2020-01-29 21:16:08,348] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/manifold/tests
[2020-01-29 21:16:08,349] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/mixture/tests
[2020-01-29 21:16:08,350] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/preprocessing/tests
[2020-01-29 21:16:08,351] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/model_selection/tests
[2020-01-29 21:16:08,353] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/decomposition/tests
[2020-01-29 21:16:08,354] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/cross_decomposition/tests
[2020-01-29 21:16:08,355] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/sklearn/neighbors/tests
[2020-01-29 21:16:08,359] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/cerberus/tests
[2020-01-29 21:16:08,368] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/odr/tests
[2020-01-29 21:16:08,369] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/misc/tests
[2020-01-29 21:16:08,370] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/cluster/tests
[2020-01-29 21:16:08,370] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/ndimage/tests
[2020-01-29 21:16:08,373] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/linalg/tests
\[2020-01-29 21:16:08,376] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/optimize/tests
[2020-01-29 21:16:08,380] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/optimize/_trustregion_constr/tests
[2020-01-29 21:16:08,381] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/integrate/tests
[2020-01-29 21:16:08,383] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/constants/tests
[2020-01-29 21:16:08,384] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/io/tests
[2020-01-29 21:16:08,392] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/io/arff/tests
[2020-01-29 21:16:08,394] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/io/harwell_boeing/tests
[2020-01-29 21:16:08,395] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/io/matlab/tests
[2020-01-29 21:16:08,406] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/_lib/tests
[2020-01-29 21:16:08,408] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/special/tests
[2020-01-29 21:16:08,413] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/fftpack/tests
[2020-01-29 21:16:08,415] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/interpolate/tests
[2020-01-29 21:16:08,417] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/fft/tests
[2020-01-29 21:16:08,418] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/fft/_pocketfft/tests
[2020-01-29 21:16:08,419] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/sparse/tests
[2020-01-29 21:16:08,420] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/sparse/linalg/tests
[2020-01-29 21:16:08,421] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/sparse/linalg/isolve/tests
[2020-01-29 21:16:08,423] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/sparse/linalg/eigen/arpack/tests
[2020-01-29 21:16:08,424] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/sparse/linalg/eigen/lobpcg/tests
[2020-01-29 21:16:08,424] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/sparse/linalg/dsolve/tests
[2020-01-29 21:16:08,425] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/sparse/csgraph/tests
[2020-01-29 21:16:08,426] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/spatial/tests
[2020-01-29 21:16:08,430] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/spatial/transform/tests
[2020-01-29 21:16:08,430] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/_build_utils/tests
[2020-01-29 21:16:08,431] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/signal/tests
[2020-01-29 21:16:08,433] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/scipy/stats/tests
[2020-01-29 21:16:08,437] DEBUG - removing dir: /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/predict/pandas/tests
-[2020-01-29 21:16:08,510] DEBUG - Checking is function "predict" bundle under lambda size limit
[2020-01-29 21:16:08,510] DEBUG - Remove module "boto3" from build directory
[2020-01-29 21:16:08,519] DEBUG - Remove module "botocore" from build directory
\[2020-01-29 21:16:08,799] DEBUG - Function predict is over lambda size limit, attempting reduce it
-[2020-01-29 21:16:08,945] DEBUG - Including "SKSentimentAnalysis" Now the current lambda function size is 84343581
[2020-01-29 21:16:08,945] DEBUG - Including "numpy" Now the current lambda function size is 154943894
[2020-01-29 21:16:08,945] DEBUG - Including "scipy" Now the current lambda function size is 224138175
[2020-01-29 21:16:08,945] DEBUG - Lambda function size 249068481 is over the limit. Moving item "pandas" out of the bundle directory
[2020-01-29 21:16:08,946] DEBUG - Including "sklearn" Now the current lambda function size is 240930610
[2020-01-29 21:16:08,946] DEBUG - Including "grpc" Now the current lambda function size is 247477457
[2020-01-29 21:16:08,946] DEBUG - Lambda function size 252778578 is over the limit. Moving item "google" out of the bundle directory
[2020-01-29 21:16:08,946] DEBUG - Lambda function size 252155290 is over the limit. Moving item "sqlalchemy" out of the bundle directory
[2020-01-29 21:16:08,946] DEBUG - Lambda function size 249335804 is over the limit. Moving item "docutils" out of the bundle directory
[2020-01-29 21:16:08,947] DEBUG - Lambda function size 249270861 is over the limit. Moving item "_ruamel_yaml.cpython-37m-x86_64-linux-gnu.so" out of the bundle directory
[2020-01-29 21:16:08,947] DEBUG - Lambda function size 249214958 is over the limit. Moving item "bentoml" out of the bundle directory
[2020-01-29 21:16:08,947] DEBUG - Including "setuptools" Now the current lambda function size is 248719627
[2020-01-29 21:16:08,947] DEBUG - Lambda function size 249707911 is over the limit. Moving item "werkzeug" out of the bundle directory
[2020-01-29 21:16:08,947] DEBUG - Lambda function size 249634811 is over the limit. Moving item "pytz" out of the bundle directory
[2020-01-29 21:16:08,948] DEBUG - Lambda function size 249548074 is over the limit. Moving item "joblib" out of the bundle directory
[2020-01-29 21:16:08,948] DEBUG - Lambda function size 249299508 is over the limit. Moving item "alembic" out of the bundle directory
[2020-01-29 21:16:08,948] DEBUG - Lambda function size 249214175 is over the limit. Moving item "ruamel" out of the bundle directory
[2020-01-29 21:16:08,949] DEBUG - Lambda function size 249178830 is over the limit. Moving item "bundled_pip_dependencies" out of the bundle directory
[2020-01-29 21:16:08,949] DEBUG - Lambda function size 249174760 is over the limit. Moving item "pkg_resources" out of the bundle directory
[2020-01-29 21:16:08,949] DEBUG - Lambda function size 249172448 is over the limit. Moving item "docker" out of the bundle directory
[2020-01-29 21:16:08,950] DEBUG - Lambda function size 249164562 is over the limit. Moving item "jinja2" out of the bundle directory
[2020-01-29 21:16:08,950] DEBUG - Lambda function size 249142788 is over the limit. Moving item "dateutil" out of the bundle directory
[2020-01-29 21:16:08,951] DEBUG - Lambda function size 249109983 is over the limit. Moving item "websocket" out of the bundle directory
[2020-01-29 21:16:08,951] DEBUG - Lambda function size 249086632 is over the limit. Moving item "chardet" out of the bundle directory
[2020-01-29 21:16:08,951] DEBUG - Lambda function size 249064681 is over the limit. Moving item "urllib3" out of the bundle directory
[2020-01-29 21:16:08,952] DEBUG - Lambda function size 249019904 is over the limit. Moving item "flask" out of the bundle directory
[2020-01-29 21:16:08,952] DEBUG - Lambda function size 249001395 is over the limit. Moving item "certifi" out of the bundle directory
[2020-01-29 21:16:08,952] DEBUG - Including "pyparsing.py" Now the current lambda function size is 248992027
[2020-01-29 21:16:08,953] DEBUG - Lambda function size 249258793 is over the limit. Moving item "click" out of the bundle directory
[2020-01-29 21:16:08,953] DEBUG - Lambda function size 249254029 is over the limit. Moving item "mako" out of the bundle directory
[2020-01-29 21:16:08,953] DEBUG - Lambda function size 249248310 is over the limit. Moving item "idna" out of the bundle directory
[2020-01-29 21:16:08,953] DEBUG - Lambda function size 249245239 is over the limit. Moving item "s3transfer" out of the bundle directory
[2020-01-29 21:16:08,954] DEBUG - Lambda function size 249241671 is over the limit. Moving item "humanfriendly" out of the bundle directory
[2020-01-29 21:16:08,954] DEBUG - Lambda function size 249227760 is over the limit. Moving item "gunicorn" out of the bundle directory
[2020-01-29 21:16:08,954] DEBUG - Lambda function size 249164562 is over the limit. Moving item "requests" out of the bundle directory
[2020-01-29 21:16:08,955] DEBUG - Lambda function size 249121362 is over the limit. Moving item "prometheus_client" out of the bundle directory
[2020-01-29 21:16:08,955] DEBUG - Lambda function size 249101527 is over the limit. Moving item "cerberus" out of the bundle directory
[2020-01-29 21:16:08,955] DEBUG - Lambda function size 249084264 is over the limit. Moving item "packaging" out of the bundle directory
[2020-01-29 21:16:08,956] DEBUG - Lambda function size 249058033 is over the limit. Moving item "markupsafe" out of the bundle directory
[2020-01-29 21:16:08,956] DEBUG - Lambda function size 249056410 is over the limit. Moving item "backports" out of the bundle directory
[2020-01-29 21:16:08,956] DEBUG - Lambda function size 249051868 is over the limit. Moving item "jmespath" out of the bundle directory
[2020-01-29 21:16:08,956] DEBUG - Lambda function size 249047486 is over the limit. Moving item "tabulate.py" out of the bundle directory
[2020-01-29 21:16:08,957] DEBUG - Lambda function size 249028860 is over the limit. Moving item "itsdangerous" out of the bundle directory
[2020-01-29 21:16:08,957] DEBUG - Lambda function size 249026101 is over the limit. Moving item "six.py" out of the bundle directory
[2020-01-29 21:16:08,957] DEBUG - Lambda function size 249001589 is over the limit. Moving item "docutils-0.15.2.data" out of the bundle directory
[2020-01-29 21:16:08,958] DEBUG - Lambda function size 249000164 is over the limit. Moving item "pythonjsonlogger" out of the bundle directory
[2020-01-29 21:16:08,958] DEBUG - Including "websocket_client-0.57.0.data" Now the current lambda function size is 248998430
[2020-01-29 21:16:08,958] DEBUG - Including "app.py" it is part of required bundle.
[2020-01-29 21:16:08,958] DEBUG - Lambda function size 249001418 is over the limit. Moving item "editor.py" out of the bundle directory
[2020-01-29 21:16:08,958] DEBUG - Including "download_extra_resources.py" it is part of required bundle.
[2020-01-29 21:16:08,958] DEBUG - Lambda function size 249000095 is over the limit. Moving item "jmespath-0.9.4.data" out of the bundle directory
[2020-01-29 21:16:08,959] DEBUG - Including "configparser.py" Now the current lambda function size is 248999976
[2020-01-29 21:16:08,959] DEBUG - Lambda function size 249000515 is over the limit. Moving item "protobuf-3.11.2-py3.7-nspkg.pth" out of the bundle directory
[2020-01-29 21:16:08,959] DEBUG - Lambda function size 249000515 is over the limit. Moving item "ruamel.yaml-0.16.6-py3.6-nspkg.pth" out of the bundle directory
[2020-01-29 21:16:08,959] DEBUG - Lambda function size 249000102 is over the limit. Moving item "easy_install.py" out of the bundle directory
[2020-01-29 21:16:08,959] DEBUG - Lambda function size 249000060 is over the limit. Moving item "requirements.txt" out of the bundle directory
[2020-01-29 21:16:08,960] DEBUG - Including "__init__.py" it is part of required bundle.
[2020-01-29 21:16:08,960] DEBUG - Final Lambda function bundle size is 248999976
/[2020-01-29 21:16:09,062] DEBUG - Additional requirement size is 50392052
[2020-01-29 21:16:09,062] DEBUG - zip up additional requirement packages
-[2020-01-29 21:16:19,247] DEBUG - Uploading requirements.tar to btml-bobo-first-sk-sentiment-544c24/bobo/first-sk-sentiment
\[2020-01-29 21:16:43,118] INFO - Packaging AWS Lambda project at /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze ...
[2020-01-29 21:16:43,118] DEBUG - Setting envar "AWS_DEFAULT_REGION" to us-west-2 for subprocess call
|[2020-01-29 21:19:20,611] DEBUG - SAM cmd ['sam', 'package', '--force-upload', '--s3-bucket', 'btml-bobo-first-sk-sentiment-544c24', '--s3-prefix', 'bobo/first-sk-sentiment/lambda-functions', '--template-file', 'template.yaml', '--output-template-file', 'packaged.yaml', '--region', 'us-west-2'] output: 
Successfully packaged artifacts and wrote output template to file packaged.yaml.
Execute the following command to deploy the packaged template
sam deploy --template-file /private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/packaged.yaml --stack-name <YOUR STACK NAME>


[2020-01-29 21:19:20,613] INFO - Deploying lambda project
[2020-01-29 21:19:20,614] DEBUG - Ensure stack "bobo-first-sk-sentiment" is ready to deploy
[2020-01-29 21:19:20,628] DEBUG - Checking stack description
/[2020-01-29 21:19:20,962] DEBUG - Stack "bobo-first-sk-sentiment"is ready to deploy
|[2020-01-29 21:19:20,962] DEBUG - Setting envar "AWS_DEFAULT_REGION" to us-west-2 for subprocess call
/[2020-01-29 21:20:11,478] DEBUG - SAM cmd ['sam', 'deploy', '--stack-name', 'bobo-first-sk-sentiment', '--capabilities', 'CAPABILITY_IAM', '--template-file', '/private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze/.aws-sam/build/packaged.yaml', '--region', 'us-west-2'] output: 
	Deploying with following values
	===============================
	Stack name                 : bobo-first-sk-sentiment
	Region                     : us-west-2
	Confirm changeset          : False
	Deployment s3 bucket       : None
	Capabilities               : ["CAPABILITY_IAM"]
	Parameter overrides        : {}

Initiating deployment
=====================

Waiting for changeset to be created..

CloudFormation stack changeset
------------------------------------------------------------------------------------------------
Operation                        LogicalResourceId                ResourceType                   
------------------------------------------------------------------------------------------------
+ Add                            ServerlessRestApiDeploymente6a   AWS::ApiGateway::Deployment    
                                 9858567                                                         
+ Add                            ServerlessRestApiProdStage       AWS::ApiGateway::Stage         
+ Add                            ServerlessRestApi                AWS::ApiGateway::RestApi       
+ Add                            predictApiPermissionProd         AWS::Lambda::Permission        
+ Add                            predictRole                      AWS::IAM::Role                 
+ Add                            predict                          AWS::Lambda::Function          
------------------------------------------------------------------------------------------------

Changeset created successfully. arn:aws:cloudformation:us-west-2:192023623294:changeSet/samcli-deploy1580361562/affdba60-aae2-456e-8f84-6e522649733d


2020-01-29 21:19:27 - Waiting for stack create/update to complete

CloudFormation events from changeset
-------------------------------------------------------------------------------------------------
ResourceStatus           ResourceType             LogicalResourceId        ResourceStatusReason   
-------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS       AWS::IAM::Role           predictRole              -                      
CREATE_IN_PROGRESS       AWS::IAM::Role           predictRole              Resource creation      
                                                                           Initiated              
CREATE_COMPLETE          AWS::IAM::Role           predictRole              -                      
CREATE_IN_PROGRESS       AWS::Lambda::Function    predict                  -                      
CREATE_COMPLETE          AWS::Lambda::Function    predict                  -                      
CREATE_IN_PROGRESS       AWS::Lambda::Function    predict                  Resource creation      
                                                                           Initiated              
CREATE_IN_PROGRESS       AWS::ApiGateway::RestA   ServerlessRestApi        -                      
                         pi                                                                       
CREATE_COMPLETE          AWS::ApiGateway::RestA   ServerlessRestApi        -                      
                         pi                                                                       
CREATE_IN_PROGRESS       AWS::ApiGateway::RestA   ServerlessRestApi        Resource creation      
                         pi                                                Initiated              
CREATE_IN_PROGRESS       AWS::ApiGateway::Deplo   ServerlessRestApiDeplo   Resource creation      
                         yment                    ymente6a9858567          Initiated              
CREATE_IN_PROGRESS       AWS::Lambda::Permissio   predictApiPermissionPr   Resource creation      
                         n                        od                       Initiated              
CREATE_IN_PROGRESS       AWS::Lambda::Permissio   predictApiPermissionPr   -                      
                         n                        od                                              
CREATE_IN_PROGRESS       AWS::ApiGateway::Deplo   ServerlessRestApiDeplo   -                      
                         yment                    ymente6a9858567                                 
CREATE_COMPLETE          AWS::ApiGateway::Deplo   ServerlessRestApiDeplo   -                      
                         yment                    ymente6a9858567                                 
CREATE_IN_PROGRESS       AWS::ApiGateway::Stage   ServerlessRestApiProdS   -                      
                                                  tage                                            
CREATE_IN_PROGRESS       AWS::ApiGateway::Stage   ServerlessRestApiProdS   Resource creation      
                                                  tage                     Initiated              
CREATE_COMPLETE          AWS::ApiGateway::Stage   ServerlessRestApiProdS   -                      
                                                  tage                                            
CREATE_COMPLETE          AWS::Lambda::Permissio   predictApiPermissionPr   -                      
                         n                        od                                              
CREATE_COMPLETE          AWS::CloudFormation::S   bobo-first-sk-           -                      
                         tack                     sentiment                                       
-------------------------------------------------------------------------------------------------

Stack bobo-first-sk-sentiment outputs:
-------------------------------------------------------------------------------------------------
OutputKey-Description                            OutputValue                                    
-------------------------------------------------------------------------------------------------
S3Bucket - S3 Bucket for saving artifacts and    btml-bobo-first-sk-sentiment-544c24            
lambda bundle                                                                                   
EndpointUrl - URL for endpoint                   https://f1ld0iaxwl.execute-api.us-             
                                                 west-2.amazonaws.com/Prod                      
-------------------------------------------------------------------------------------------------

Successfully created/updated stack - bobo-first-sk-sentiment in us-west-2


[2020-01-29 21:20:11,486] DEBUG - BentoML in debug mode, keeping temp directory "/private/var/folders/kn/xnc9k74x03567n1mx2tfqnpr0000gn/T/bentoml-temp-lke6jrze"
|[2020-01-29 21:20:11,503] INFO - ApplyDeployment (first-sk-sentiment, namespace bobo) succeeded
Successfully created AWS Lambda deployment first-sk-sentiment
{
  "namespace": "bobo",
  "name": "first-sk-sentiment",
  "spec": {
    "bentoName": "SKSentimentAnalysis",
    "bentoVersion": "20200129210903_E48487",
    "operator": "AWS_LAMBDA",
    "awsLambdaOperatorConfig": {
      "region": "us-west-2",
      "apiName": "predict",
      "memorySize": 1024,
      "timeout": 3
    }
  },
  "state": {
    "state": "RUNNING",
    "infoJson": {
      "endpoints": [
        "https://f1ld0iaxwl.execute-api.us-west-2.amazonaws.com/Prod/predict"
      ],
      "s3_bucket": "btml-bobo-first-sk-sentiment-544c24"
    },
    "timestamp": "2020-01-30T05:20:12.037422Z"
  },
  "createdAt": "2020-01-30T05:13:45.570995Z",
  "lastUpdatedAt": "2020-01-30T05:13:45.571039Z"
}

To get the latest status of your Lambda deployment use bentoml lambda get command

In [71]:
!bentoml lambda get first-sk-sentiment
{
  "namespace": "bobo",
  "name": "first-sk-sentiment",
  "spec": {
    "bentoName": "SKSentimentAnalysis",
    "bentoVersion": "20200129205654_0D29B1",
    "operator": "AWS_LAMBDA",
    "awsLambdaOperatorConfig": {
      "region": "us-west-2",
      "apiName": "predict",
      "memorySize": 1024,
      "timeout": 3
    }
  },
  "state": {
    "state": "RUNNING",
    "infoJson": {
      "endpoints": [
        "https://9enzosx6o0.execute-api.us-west-2.amazonaws.com/Prod/predict"
      ],
      "s3_bucket": "btml-bobo-first-sk-sentiment-30f9a3"
    },
    "timestamp": "2020-01-30T05:07:19.365714Z"
  },
  "createdAt": "2020-01-30T05:00:21.369618Z",
  "lastUpdatedAt": "2020-01-30T05:00:21.369666Z"
}
In [79]:
!curl -i \
--header "Content-Type: application/json" \
--request POST \
--data '["some new text, sweet noodles", "happy time", "sad day"]' \
https://f1ld0iaxwl.execute-api.us-west-2.amazonaws.com/Prod/predict











[4, 4, 0]

**bentoml lambda list will display all Lambda deployments

In [50]:
!bentoml lambda list
NAME                NAMESPACE    LABELS    PLATFORM    STATUS    AGE
first-sk-sentiment  bobo                   aws-lambda  running   7 minutes and 33 seconds

Delete Lambda deployment with bentoml lambda delete, this will also remove all related resources

In [73]:
!bentoml lambda delete first-sk-sentiment
Successfully deleted AWS Lambda deployment "first-sk-sentiment"