Ensure not exceed AWS string length for sagemaker
@@ -105,21 +105,12 @@ def strip_scheme(url):
def generate_aws_compatible_string(item):
pattern = re.compile("[^a-zA-Z0-9-]|_")
- return re.sub(pattern, "-", item)
-
-
-def _get_sagemaker_model_name(bento_name, bento_version):
- return generate_aws_compatible_string(
- "bentoml-{name}-{version}".format(name=bento_name, version=bento_version)
- )
-
-
-def _get_sagemaker_endpoint_config_name(bento_name, bento_version):
- return generate_aws_compatible_string(
- 'bentoml-{name}-{version}-configuration'.format(
- name=bento_name, version=bento_version
- )
+ name = re.sub(pattern, "-", item)
+ if len(name) > 63:
+ raise BentoMLException(
+ 'AWS string {} exceeds Sagemaker maximum length of 63'.format(name)
)
+ return name
def get_arn_role_from_current_aws_user():
@@ -251,7 +242,7 @@ def _parse_aws_client_exception(e):
def _cleanup_sagemaker_model(client, name, version):
- model_name = _get_sagemaker_model_name(name, version)
+ model_name = generate_aws_compatible_string(name + '-' + version)
try:
delete_model_response = client.delete_model(ModelName=model_name)
logger.debug("AWS delete model response: %s", delete_model_response)
@@ -262,7 +253,7 @@ def _cleanup_sagemaker_model(client, name, version):
def _cleanup_sagemaker_endpoint_config(client, name, version):
- endpoint_config_name = _get_sagemaker_endpoint_config_name(name, version)
+ endpoint_config_name = generate_aws_compatible_string(name + '-' + version)
try:
delete_endpoint_config_response = client.delete_endpoint_config(
EndpointConfigName=endpoint_config_name
@@ -298,7 +289,7 @@ def _create_sagemaker_model(
sagemaker_client, bento_name, bento_version, ecr_image_path, api_name
):
execution_role_arn = get_arn_role_from_current_aws_user()
- model_name = _get_sagemaker_model_name(bento_name, bento_version)
+ model_name = generate_aws_compatible_string(bento_name + '-' + bento_version)
sagemaker_model_info = {
"ModelName": model_name,
@@ -333,8 +324,8 @@ def _create_sagemaker_endpoint_config(
"InstanceType": sagemaker_config.instance_type,
}
]
- endpoint_config_name = _get_sagemaker_endpoint_config_name(
- bento_name, bento_version
+ endpoint_config_name = generate_aws_compatible_string(
+ bento_name + '-' + bento_version
)
logger.debug("Creating Sagemaker endpoint %s configuration", endpoint_config_name)
