Update a Sagemaker Endpoint when changing the docker image

1.6k views Asked by At

I am looking for the simplest solution for updating a Sagemaker Endpoint. The only thing I want to change is the docker image (to update the code).

I am building the new Docker image on my computer, and then I upload it on ECR (I plan to do this in a CI/CD in the near future).

From my understanding, it seems that the simplest way is to create a new EndpointConfig, then call the UpdateEndpoint API to switch the endpoint to the new config, then delete the old EndpointConfig. Does anyone know a simpler way? Or can anyone confirm that this is the simplest approach to doing this?

1

There are 1 answers

1
skibee On

My solution is to use boto3 sagemaker client which has the update_enpoint method.

Here is a pseudo code in python

  1. first create_model with the updated docker image
session = boto3.Session()
sm_client = session.client('sagemaker')

sm_client.create_model(
            ModelName = cfg.sagemaker.ENDPOINT_NAME,
            ExecutionRoleArn = ROLE_ARN,
            PrimaryContainer = {
                'Image': AWS_IMAGE_FULLNAME,
                'ModelDataUrl': MODEL_CLOUD_PACKAGE,
            }
        )
  1. create a new endpoint_config
sm_client.create_endpoint_config(
                EndpointConfigName=CONFIG_NAME,
                ProductionVariants=[{...}],
            )
  1. update_enpoint
sm_client.update_endpoint(
                EndpointName=ENDPOINT_NAME,
                EndpointConfigName=CONFIG_NAME,
            )