def test_aws_lambda_describe_success():
    def mock_cf_response(_self, op_name, _kwarg):
        if op_name == 'DescribeStacks':
            return {
                'Stacks': [{
                    'StackStatus':
                    'CREATE_COMPLETE',
                    'Outputs': [{
                        'OutputKey':
                        'EndpointUrl',
                        'OutputValue':
                        'https://somefakelink.amazonaws.com'
                        '/prod/predict',
                    }],
                }]
            }
        else:
            raise Exception(
                'This test does not handle operation {}'.format(op_name))

    yatai_service_mock = create_yatai_service_mock()
    test_deployment_pb = generate_lambda_deployment_pb()
    with patch(
            'bentoml.yatai.deployment.aws_lambda.operator.get_default_aws_region',
            MagicMock(return_value='mock_region'),
    ):
        with patch('botocore.client.BaseClient._make_api_call',
                   new=mock_cf_response):
            deployment_operator = AwsLambdaDeploymentOperator(
                yatai_service_mock)
            result_pb = deployment_operator.describe(test_deployment_pb)
            assert result_pb.status.status_code == status_pb2.Status.OK
            assert result_pb.state.state == DeploymentState.RUNNING
예제 #2
0
def test_aws_lambda_apply_over_max_bundle_size_limit_fail():
    yatai_service_mock = create_yatai_service_mock()
    test_deployment_pb = generate_lambda_deployment_pb()
    deployment_operator = AwsLambdaDeploymentOperator(yatai_service_mock)
    result_pb = deployment_operator.add(test_deployment_pb)
    assert result_pb.status.status_code == status_pb2.Status.INTERNAL
    assert result_pb.deployment.state.state == DeploymentState.ERROR
def test_aws_lambda_apply_over_bundle_size_limit_success():
    yatai_service_mock = create_yatai_service_mock()
    test_deployment_pb = generate_lambda_deployment_pb()
    deployment_operator = AwsLambdaDeploymentOperator(yatai_service_mock)

    result_pb = deployment_operator.add(test_deployment_pb)

    assert result_pb.status.status_code == status_pb2.Status.OK
    assert result_pb.deployment.state.state == DeploymentState.PENDING
예제 #4
0
def get_deployment_operator(yatai_service, deployment_pb):
    operator = deployment_pb.spec.operator

    if operator == DeploymentSpec.AWS_SAGEMAKER:
        from bentoml.yatai.deployment.sagemaker.operator import (
            SageMakerDeploymentOperator, )

        return SageMakerDeploymentOperator(yatai_service)
    elif operator == DeploymentSpec.AWS_LAMBDA:
        from bentoml.yatai.deployment.aws_lambda.operator import (
            AwsLambdaDeploymentOperator, )

        return AwsLambdaDeploymentOperator(yatai_service)
    elif operator == DeploymentSpec.GCP_FUNCTION:
        raise NotImplementedError(
            "GCP Function deployment operator is not supported in current version of "
            "BentoML")
    elif operator == DeploymentSpec.KUBERNETES:
        raise NotImplementedError(
            "Kubernetes deployment operator is not supported in current version of "
            "BentoML")
    elif operator == DeploymentSpec.CUSTOM:
        raise NotImplementedError(
            "Custom deployment operator is not supported in current version of BentoML"
        )
    else:
        raise YataiDeploymentException("DeployOperator must be set")
예제 #5
0
def get_deployment_operator(yatai_service, deployment_pb):
    operator = deployment_pb.spec.operator

    if operator == DeploymentSpec.AWS_SAGEMAKER:
        from bentoml.yatai.deployment.sagemaker.operator import (
            SageMakerDeploymentOperator, )

        return SageMakerDeploymentOperator(yatai_service)
    elif operator == DeploymentSpec.AWS_LAMBDA:
        from bentoml.yatai.deployment.aws_lambda.operator import (
            AwsLambdaDeploymentOperator, )

        return AwsLambdaDeploymentOperator(yatai_service)
    elif operator == DeploymentSpec.AZURE_FUNCTIONS:
        from bentoml.yatai.deployment.azure_functions.operator import (
            AzureFunctionsDeploymentOperator, )

        return AzureFunctionsDeploymentOperator(yatai_service)
    elif operator == DeploymentSpec.AWS_EC2:
        from bentoml.yatai.deployment.aws_ec2.operator import AwsEc2DeploymentOperator

        return AwsEc2DeploymentOperator(yatai_service)
    elif operator == DeploymentSpec.CUSTOM:
        raise NotImplementedError(
            "Custom deployment operator is not supported in current version of BentoML"
        )
    else:
        raise YataiDeploymentException("DeployOperator must be set")
def test_aws_lambda_describe_still_in_progress():
    def mock_cf_response(_self, op_name, _kwarg):
        if op_name == 'DescribeStacks':
            return {'Stacks': [{'StackStatus': 'CREATE_IN_PROGRESS'}]}
        else:
            raise Exception('This test does not handle operation {}'.format(op_name))

    yatai_service_mock = create_yatai_service_mock()
    test_deployment_pb = generate_lambda_deployment_pb()
    with patch(
        'bentoml.yatai.deployment.aws_lambda.operator.get_default_aws_region',
        MagicMock(return_value='mock_region'),
    ):
        with patch('botocore.client.BaseClient._make_api_call', new=mock_cf_response):
            deployment_operator = AwsLambdaDeploymentOperator(yatai_service_mock)
            result_pb = deployment_operator.describe(test_deployment_pb)
            assert result_pb.status.status_code == status_pb2.Status.OK
            assert result_pb.state.state == DeploymentState.PENDING