Skip to content

Commit

Permalink
fix serverless deployment issues (#296)
Browse files Browse the repository at this point in the history
* fix issue determine aws lambda env

* use function load for loading model service
  • Loading branch information
yubozhao authored Sep 17, 2019
1 parent c4482a0 commit becf4a2
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
18 changes: 11 additions & 7 deletions bentoml/deployment/serverless/aws_lambda.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@
# Set BENTOML_HOME to /tmp directory due to AWS lambda disk access restrictions
os.environ['BENTOML_HOME'] = '/tmp/bentoml/'
from {class_name} import {class_name}
from {class_name} import load
bento_service = {class_name}.load()
bento_service = load()
"""

Expand Down Expand Up @@ -133,7 +133,7 @@ def apply(self, deployment_pb, repo, prev_deployment=None):
template = 'aws-python3'
minimum_python_version = version.parse('3.0.0')
bento_python_version = version.parse(bento_config['env']['python_version'])
if bento_python_version > minimum_python_version:
if bento_python_version < minimum_python_version:
template = 'aws-python'

with TemporaryServerlessContent(
Expand All @@ -153,8 +153,8 @@ def apply(self, deployment_pb, repo, prev_deployment=None):
stage=deployment_pb.namespace,
)
logger.info(
'Installing additional packages: serverless-python-requirements, \
serverless-apigw-binary'
'Installing additional packages: serverless-python-requirements, '
'serverless-apigw-binary'
)
install_serverless_plugin("serverless-python-requirements", output_path)
install_serverless_plugin("serverless-apigw-binary", output_path)
Expand All @@ -170,8 +170,12 @@ def apply(self, deployment_pb, repo, prev_deployment=None):
def delete(self, deployment_pb, repo=None):
state = self.describe(deployment_pb, repo).state
if state.state != DeploymentState.RUNNING:
message = 'Failed to delete, no active deployment {name}. The current state is {state}'.format(
name=deployment_pb.name, state=DeploymentState.State.Name(state.state)
message = (
'Failed to delete, no active deployment {name}. '
'The current state is {state}'.format(
name=deployment_pb.name,
state=DeploymentState.State.Name(state.state),
)
)
return DeleteDeploymentResponse(status=Status.ABORTED(message))

Expand Down
12 changes: 8 additions & 4 deletions bentoml/deployment/serverless/gcp_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
logger = logging.getLogger(__name__)

GOOGLE_MAIN_PY_TEMPLATE_HEADER = """\
from {class_name} import {class_name}
from {class_name} import load
bento_service = {class_name}.load()
bento_service = load()
"""

Expand Down Expand Up @@ -161,8 +161,12 @@ def describe(self, deployment_pb, repo=None):
def delete(self, deployment_pb, repo=None):
state = self.describe(deployment_pb, repo).state
if state.state != DeploymentState.RUNNING:
message = 'Failed to delete, no active deployment {name}. The current state is {state}'.format(
name=deployment_pb.name, state=DeploymentState.State.Name(state.state)
message = (
'Failed to delete, no active deployment {name}. '
'The current state is {state}'.format(
name=deployment_pb.name,
state=DeploymentState.State.Name(state.state),
)
)
return DeleteDeploymentResponse(status=Status.ABORTED(message))

Expand Down
7 changes: 5 additions & 2 deletions bentoml/deployment/serverless/serverless_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,12 @@ def parse_serverless_response(serverless_response):

def parse_serverless_info_response_to_json_string(responses):
result = {}
for line in responses:
for i in range(len(responses)):
line = responses[i]
if ': ' in line:
items = line.split(': ')
result[items[0]] = items[1]
result['raw_response'] = responses
return json.dumps(result)


Expand Down Expand Up @@ -129,7 +131,8 @@ def generate(self):
)
shutil.copy(os.path.join(self.archive_path, "requirements.txt"), tempdir)
model_serivce_archive_path = os.path.join(tempdir, self.bento_name)
shutil.copytree(self.archive_path, model_serivce_archive_path)
model_path = os.path.join(self.archive_path, self.bento_name)
shutil.copytree(model_path, model_serivce_archive_path)
self.path = tempdir

def cleanup(self):
Expand Down

0 comments on commit becf4a2

Please sign in to comment.