Vinayak Shanawad
Vinayak Shanawad

Reputation: 21

Not able to create an sagemaker endpoint with datacaptureconfig enabled using boto3 API

SageMaker version: 2.129.0

boto3 version: 1.26.57

Error details: ClientError: An error occurred (ValidationException) when calling the CreateEndpoint operation: One or more endpoint features are not supported using this configuration.

Steps to replicate the above issue:

# Download model
!aws s3 cp s3://sagemaker-sample-files/models/xgb-churn/xgb-churn-prediction-model.tar.gz model/
# Step 1 – Create model
import boto3
from sagemaker.s3 import S3Uploader
import datetime
from sagemaker import get_execution_role

bucket = "sagemaker-us-east-x-xxxxxxxxxx"
prefix = "sagemaker/xgb"

sagemaker_session = sagemaker.Session()
region = sagemaker_session.boto_session.region_name
sm_boto3 = boto3.client("sagemaker")

model_url = S3Uploader.upload(
    local_path="model/xgb-churn-prediction-model.tar.gz",
    desired_s3_uri=f"s3://{bucket}/{prefix}",
)

from sagemaker import image_uris
image_uri = image_uris.retrieve("xgboost", region, "0.90-1")

model_name = f"DEMO-xgb-churn-pred-model-{datetime.datetime.now():%Y-%m-%d-%H-%M-%S}"

resp = sm_boto3.create_model(
    ModelName=model_name,
    ExecutionRoleArn=get_execution_role(),
    Containers=[{"Image": image_uri, "ModelDataUrl": model_url}],
)
# Step 2 – Create endpoint config
epc_name = f"DEMO-xgb-churn-pred-epc-{datetime.datetime.now():%Y-%m-%d-%H-%M-%S}"

endpoint_config_response = sm_boto3.create_endpoint_config(
    EndpointConfigName = epc_name,
    ProductionVariants=[
        {
        'InstanceType':'ml.m5.xlarge',
        'InitialInstanceCount':1,
        'ModelName':model_name,
        'VariantName':'production',
        'InitialVariantWeight':1
        }
    ],
    DataCaptureConfig={
        'EnableCapture': True,
        'InitialSamplingPercentage': 50,
        'DestinationS3Uri': 's3://sagemaker-us-east-x-xxxxxxxxxx/sagemaker/xgb/',
        'CaptureOptions': [
            {
                'CaptureMode': 'InputAndOutput'
            },
        ],
        'CaptureContentTypeHeader': {
            'JsonContentTypes': [
                'application/json',
            ]
        }
    }
    )

print('Endpoint configuration name: {}'.format(epc_name))
print('Endpoint configuration arn:  {}'.format(endpoint_config_response['EndpointConfigArn']))
# Step 3 - Create endpoint
endpoint_name = f"DEMO-xgb-churn-pred-ep-{datetime.datetime.now():%Y-%m-%d-%H-%M-%S}"

endpoint_params = {
    'EndpointName': endpoint_name,
    'EndpointConfigName': epc_name,
}
endpoint_response = sm_boto3.create_endpoint(EndpointName=endpoint_name, EndpointConfigName=epc_name)
print('EndpointArn = {}'.format(endpoint_response['EndpointArn']))

Expected behaviour: Should able to create an endpoint with data capture enabled using boto3 API.

Upvotes: 2

Views: 885

Answers (1)

vikrame
vikrame

Reputation: 485

I was able to replicate your set up and it works for me as expected. I am using a higher version of boto3 and SageMaker, consider upgrading both and give it a try !

boto3 version - 1.26.62 sagemaker version - 2.131.0

Upvotes: 0

Related Questions