Skip to content

Commit

Permalink
improve e2e lambda test, fix lambda deployment bug (#449)
Browse files Browse the repository at this point in the history
* small fix

* remove unused import

* add notes
  • Loading branch information
yubozhao committed Dec 20, 2019
1 parent 104698d commit 87bf227
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 20 deletions.
13 changes: 11 additions & 2 deletions bentoml/deployment/aws_lambda/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,8 +393,17 @@ def ensure_is_ready_to_deploy_to_cloud_formation(stack_name, region):
'Stack "%s" is in a "bad" status(%s), deleting the stack '
'before deployment',
stack_name,
stack_result['StackStatus']
stack_result['StackStatus'],
)
cf_client.delete_stack(StackName=stack_name)
except ClientError as e:
raise BentoMLException(str(e))
# We are brutally parse and handle stack doesn't exist, since
# "AmazonCloudFormationException" currently is not implemented in boto3. Once
# the current error is implemented, we need to switch
error_response = e.response.get('Error', {})
error_code = error_response.get('Code')
error_message = error_response.get('Message', 'Unknown')
if error_code == 'ValidationError' and 'does not exist' in error_message:
pass
else:
raise BentoMLException(str(e))
43 changes: 25 additions & 18 deletions scripts/e2e_tests/aws_lambda/e2e_lambda_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import logging
import uuid
import sys

import requests
import json
Expand All @@ -25,27 +26,33 @@ def predict(self, df):


if __name__ == '__main__':
logger.info('Training iris classifier with sklearn..')
clf = svm.SVC(gamma='scale')
iris = datasets.load_iris()
X, y = iris.data, iris.target
clf.fit(X, y)

logger.info('Creating iris classifier BentoService bundle..')
iris_clf_service = IrisClassifier()
iris_clf_service.pack('clf', clf)
saved_path = iris_clf_service.save()

loaded_service = load(saved_path)
sample_data = X[0:1]

logger.info(
'Result from sample data is: %s', str(loaded_service.predict(sample_data))
)
deployment_failed = False
bento_name = f'{loaded_service.name}:{loaded_service.version}'
random_hash = uuid.uuid4().hex[:6]
deployment_name = f'tests-lambda-e2e-{random_hash}'

args = sys.argv
bento_name = None
if len(args) > 1:
bento_name = args[1]
if bento_name is None:
logger.info('Training iris classifier with sklearn..')
clf = svm.SVC(gamma='scale')
iris = datasets.load_iris()
X, y = iris.data, iris.target
clf.fit(X, y)

logger.info('Creating iris classifier BentoService bundle..')
iris_clf_service = IrisClassifier()
iris_clf_service.pack('clf', clf)
saved_path = iris_clf_service.save()

loaded_service = load(saved_path)
sample_data = X[0:1]

logger.info(
'Result from sample data is: %s', str(loaded_service.predict(sample_data))
)
bento_name = f'{loaded_service.name}:{loaded_service.version}'
create_deployment_command = [
'bentoml',
'--verbose',
Expand Down

0 comments on commit 87bf227

Please sign in to comment.