Skip to content
Browse files

Serverless implementation refactor and add api-name option for server…

…less deployment (#324)

* Add api_name as param for lambda/gcp

* use user defined api_name

* add validation for serverless api_name

* use boto3 to find aws lambda info

* add validation for api_name option

* make sure we catch exception from delete operation

* make sure catch exception from describe as well

* better handle for bentoml exceptions in operator

* wrap try/catch outside operator actions

* clean up imports

* add python version as part of bento service metadata

* set python version for BentoServiceMetadata proto

* use load_service_metadata for deployment

* make sure use metadata

* dynamic import Status

* make sure use bento config metadata

* use yatai service instead of repo as part of operator signature

* refactor serverless deployment

* remove temp project generator for serverless

* clean up
  • Loading branch information...
yubozhao authored and parano committed Oct 8, 2019
1 parent 78c6d6a commit cd8a0ba65baf66a9a77939b3302d5323ef3c30c4
@@ -61,6 +61,8 @@ def load_bento_service_metadata(archive_path):
bento_service_metadata.env.pip_dependencies = "\n".join(
if "python_version" in config["env"]:
bento_service_metadata.env.python_version = config["env"]["python_version"]

if "apis" in config:
for api_config in config["apis"]:
@@ -19,6 +19,7 @@
import click
import logging
import time
import json

from google.protobuf.json_format import MessageToJson
from bentoml.cli.click_utils import (
@@ -65,11 +66,16 @@ def parse_key_value_pairs(key_value_pairs_str):
return result

def display_deployment_info(deployment, output):
if output == 'yaml':
def display_deployment_info(deployment, output_type):
if output_type == 'yaml':
result = pb_to_yaml(deployment)
result = MessageToJson(deployment)
if deployment.state.info_json:
result = json.loads(result)
result['state']['infoJson'] = json.loads(deployment.state.info_json)
_echo(json.dumps(result, indent=2, separators=(',', ': ')))

@@ -151,7 +157,7 @@ def deployment():
help='Type of instance will be used for inference. Option applicable to '
'platform: AWS SageMaker',
'platform: AWS SageMaker, AWS Lambda, GCP Function',
@@ -244,11 +250,15 @@ def create(
aws_lambda_operator_config = DeploymentSpec.AwsLambdaOperatorConfig(
region=region or config().get('aws', 'default_region')
if api_name:
aws_lambda_operator_config.api_name = api_name
spec = DeploymentSpec(aws_lambda_operator_config=aws_lambda_operator_config)
elif operator == DeploymentSpec.GCP_FUNCTION:
gcp_function_operator_config = DeploymentSpec.GcpFunctionOperatorConfig(
region=region or config().get('google-cloud', 'default_region')
if api_name:
gcp_function_operator_config.api_name = api_name
spec = DeploymentSpec(
@@ -385,7 +395,11 @@ def delete(name, namespace, force):
deployment_name=name, namespace=namespace, force_delete=force
if result.status.status_code != Status.OK:
if result.status.status_code == Status.OK:
'Successfully deleted deployment "{}"'.format(name), CLI_COLOR_SUCCESS
'Failed to delete deployment {name}. code: {error_code}, message: '
@@ -395,7 +409,6 @@ def delete(name, namespace, force):
_echo('Successfully deleted deployment "{}"'.format(name), CLI_COLOR_SUCCESS)

@deployment.command(help='Get deployment current state')
@click.argument("name", type=click.STRING, required=True)
@@ -51,21 +51,21 @@ def get_deployment_operator(deployment_pb):
class DeploymentOperatorBase(object):
def apply(self, deployment_pb, repo, prev_deployment):
def apply(self, deployment_pb, yatai_service, prev_deployment):
Create deployment based on deployment_pb spec - the bento name and version
must be found in the given BentoRepository

def delete(self, deployment_pb, repo):
def delete(self, deployment_pb, yatai_service):
Delete deployment based on deployment_pb spec - the bento name and version
must be found in the given BentoRepository

def describe(self, deployment_pb, repo):
def describe(self, deployment_pb, yatai_service):
Fetch status on an existing deployment created with deployment_pb spec - the
bento name and version must be found in the given BentoRepository

0 comments on commit cd8a0ba

Please sign in to comment.
You can’t perform that action at this time.