aws-samples / amazon-sagemaker-safe-deployment-pipeline

Safe blue/green deployment of Amazon SageMaker endpoints using AWS CodePipeline, CodeBuild and CodeDeploy.
https://aws.amazon.com/blogs/machine-learning/safely-deploying-and-monitoring-amazon-sagemaker-endpoints-with-aws-codepipeline-and-aws-codedeploy/
MIT No Attribution
103 stars 239 forks source link

enhancement: Add support for Version 2.x of SageMaker Python SDK #8

Closed brightsparc closed 4 years ago

brightsparc commented 4 years ago

Update build code and notebook to support the breaking changes coming in v2.0 of SageMaker Python SDK

Image URI Functions (e.g. get_image_uri)

try:
    # Support SageMaker 2 SDK: https://sagemaker.readthedocs.io/en/stable/v2.html
    def get_training_image(region=None):
        region = region or boto3.Session().region_name
        return sagemaker.image_uris.retrieve(region=region, 
                                             framework='xgboost', version="1.0-1")
except:
    from sagemaker.amazon.amazon_estimator import get_image_uri
    def get_training_image(region=None):
        region = region or boto3.Session().region_name
        return get_image_uri(region, "xgboost", "1.0-1")

XGBoost Predictor

try:
    # Support SageMaker 2 SDK: https://sagemaker.readthedocs.io/en/stable/v2.html
    from sagemaker.predictor import Predictor
    from sagemaker.serializers import CSVSerializer
    def get_predictor(endpoint_name):
        xgb_predictor = Predictor(endpoint_name)
        xgb_predictor.serializer = CSVSerializer()
        return xgb_predictor
except Exception as e:
    from sagemaker.predictor import RealTimePredictor, csv_serializer
    def get_predictor(endpoint_name):
        xgb_predictor = RealTimePredictor(endpoint_name)
        xgb_predictor.content_type = 'text/csv'
        xgb_predictor.serializer = csv_serializer
        return xgb_predictor    
brightsparc commented 4 years ago

Resolved with PR #9