@@ -1006,6 +1006,52 @@ def endpoint_from_production_variants(
10061006 str: The name of the created ``Endpoint``.
10071007 """
10081008
1009+ config_options = self ._build_endpoint_config_request (
1010+ name = name ,
1011+ production_variants = production_variants ,
1012+ tags = tags ,
1013+ kms_key = kms_key ,
1014+ data_capture_config_dict = data_capture_config_dict ,
1015+ async_inference_config_dict = async_inference_config_dict ,
1016+ explainer_config_dict = explainer_config_dict ,
1017+ vpc_config = vpc_config ,
1018+ enable_network_isolation = enable_network_isolation ,
1019+ role = role ,
1020+ )
1021+ endpoint_tags = _append_project_tags (format_tags (tags ))
1022+
1023+ logger .info ("Creating endpoint-config with name %s" , name )
1024+ self .sagemaker_client .create_endpoint_config (** config_options )
1025+
1026+ return self .create_endpoint (
1027+ endpoint_name = name ,
1028+ config_name = name ,
1029+ tags = endpoint_tags ,
1030+ wait = wait ,
1031+ live_logging = live_logging ,
1032+ )
1033+
1034+ def _build_endpoint_config_request (
1035+ self ,
1036+ name ,
1037+ production_variants ,
1038+ tags = None ,
1039+ kms_key = None ,
1040+ data_capture_config_dict = None ,
1041+ async_inference_config_dict = None ,
1042+ explainer_config_dict = None ,
1043+ vpc_config = None ,
1044+ enable_network_isolation = None ,
1045+ role = None ,
1046+ ):
1047+ """Build the ``CreateEndpointConfig`` request, applying config defaults.
1048+
1049+ Shared by ``create_endpoint_config`` and
1050+ ``endpoint_from_production_variants`` so the two cannot drift.
1051+
1052+ Returns:
1053+ dict: The ``CreateEndpointConfig`` request.
1054+ """
10091055 supports_kms = any (
10101056 [
10111057 instance_supports_kms (production_variant ["InstanceType" ])
@@ -1060,7 +1106,6 @@ def endpoint_from_production_variants(
10601106 role = self .expand_role (role )
10611107 config_options ["ExecutionRoleArn" ] = role
10621108 endpoint_config_tags = _append_project_tags (format_tags (tags ))
1063- endpoint_tags = _append_project_tags (format_tags (tags ))
10641109
10651110 endpoint_config_tags = self ._append_sagemaker_config_tags (
10661111 endpoint_config_tags , "{}.{}.{}" .format (SAGEMAKER , ENDPOINT_CONFIG , TAGS )
@@ -1090,15 +1135,71 @@ def endpoint_from_production_variants(
10901135 if role is not None :
10911136 config_options ["ExecutionRoleArn" ] = role
10921137
1093- logger .info ("Creating endpoint-config with name %s" , name )
1094- self .sagemaker_client .create_endpoint_config (** config_options )
1138+ return config_options
10951139
1096- return self .create_endpoint (
1097- endpoint_name = name ,
1098- config_name = name ,
1099- tags = endpoint_tags ,
1100- wait = wait ,
1101- live_logging = live_logging ,
1140+ def create_endpoint_config (
1141+ self ,
1142+ name ,
1143+ production_variants ,
1144+ tags = None ,
1145+ kms_key = None ,
1146+ data_capture_config_dict = None ,
1147+ async_inference_config_dict = None ,
1148+ explainer_config_dict = None ,
1149+ vpc_config = None ,
1150+ enable_network_isolation = None ,
1151+ role = None ,
1152+ ):
1153+ """Create an Amazon SageMaker endpoint configuration and nothing else.
1154+
1155+ Unlike ``endpoint_from_production_variants``, which creates an endpoint
1156+ configuration *and* the endpoint that uses it, this creates only the
1157+ configuration. That makes it the producer for a pipeline
1158+ ``EndpointConfigStep``, which composes one resource per step.
1159+
1160+ Args:
1161+ name (str): Name of the endpoint configuration to create.
1162+ production_variants (list[dict[str, str]]): The list of production
1163+ variants to host at this endpoint.
1164+ tags (Optional[Tags]): Tags to apply to the endpoint configuration.
1165+ kms_key (str): KMS key ARN for encrypting the volume attached to the
1166+ instances hosting the endpoint.
1167+ data_capture_config_dict (dict): Configuration for capturing
1168+ inference request and response data.
1169+ async_inference_config_dict (dict): Configuration for asynchronous
1170+ inference.
1171+ explainer_config_dict (dict): Configuration for online explainers.
1172+ vpc_config (dict): The VpcConfig for the endpoint configuration.
1173+ enable_network_isolation (bool): Whether to isolate the model
1174+ containers deployed to the endpoint.
1175+ role (str): An execution role ARN, required when the production
1176+ variants carry no model name, as with inference components.
1177+
1178+ Returns:
1179+ str: Name of the endpoint configuration created. Under a
1180+ ``PipelineSession`` the captured step arguments are returned
1181+ instead and no service call is made.
1182+ """
1183+ config_options = self ._build_endpoint_config_request (
1184+ name = name ,
1185+ production_variants = production_variants ,
1186+ tags = tags ,
1187+ kms_key = kms_key ,
1188+ data_capture_config_dict = data_capture_config_dict ,
1189+ async_inference_config_dict = async_inference_config_dict ,
1190+ explainer_config_dict = explainer_config_dict ,
1191+ vpc_config = vpc_config ,
1192+ enable_network_isolation = enable_network_isolation ,
1193+ role = role ,
1194+ )
1195+
1196+ def submit (request ):
1197+ logger .info ("Creating endpoint-config with name %s" , name )
1198+ self .sagemaker_client .create_endpoint_config (** request )
1199+ return name
1200+
1201+ return self ._intercept_create_request (
1202+ config_options , submit , self .create_endpoint_config .__name__
11021203 )
11031204
11041205 def create_endpoint (self , endpoint_name , config_name , tags = None , wait = True , live_logging = False ):
@@ -1122,23 +1223,31 @@ def create_endpoint(self, endpoint_name, config_name, tags=None, wait=True, live
11221223 botocore.exceptions.ClientError: If Sagemaker throws an exception while creating
11231224 endpoint.
11241225 """
1125- logger .info ("Creating endpoint with name %s" , endpoint_name )
1126-
11271226 tags = format_tags (tags ) or []
11281227 tags = _append_project_tags (tags )
11291228 tags = self ._append_sagemaker_config_tags (
11301229 tags , "{}.{}.{}" .format (SAGEMAKER , ENDPOINT , TAGS )
11311230 )
1132- try :
1133- res = self .sagemaker_client .create_endpoint (
1134- EndpointName = endpoint_name , EndpointConfigName = config_name , Tags = tags
1135- )
1231+ create_endpoint_request = {
1232+ "EndpointName" : endpoint_name ,
1233+ "EndpointConfigName" : config_name ,
1234+ "Tags" : tags ,
1235+ }
1236+
1237+ def submit (request ):
1238+ logger .info ("Creating endpoint with name %s" , endpoint_name )
1239+ res = self .sagemaker_client .create_endpoint (** request )
11361240 if res :
11371241 self .endpoint_arn = res ["EndpointArn" ]
11381242
11391243 if wait :
11401244 self .wait_for_endpoint (endpoint_name , live_logging = live_logging )
11411245 return endpoint_name
1246+
1247+ try :
1248+ return self ._intercept_create_request (
1249+ create_endpoint_request , submit , self .create_endpoint .__name__
1250+ )
11421251 except Exception as e :
11431252 troubleshooting = (
11441253 "https://docs.aws.amazon.com/sagemaker/latest/dg/"
@@ -1232,12 +1341,6 @@ def create_inference_component(
12321341 Returns:
12331342 str: Name of the Amazon SageMaker ``InferenceComponent`` if created.
12341343 """
1235- LOGGER .info (
1236- "Creating inference component with name %s for endpoint %s" ,
1237- inference_component_name ,
1238- endpoint_name ,
1239- )
1240-
12411344 if runtime_config is None :
12421345 runtime_config = {"CopyCount" : 1 }
12431346
@@ -1257,10 +1360,20 @@ def create_inference_component(
12571360 if tags and len (tags ) != 0 :
12581361 request ["Tags" ] = tags
12591362
1260- self .sagemaker_client .create_inference_component (** request )
1261- if wait :
1262- self .wait_for_inference_component (inference_component_name )
1263- return inference_component_name
1363+ def submit (req ):
1364+ LOGGER .info (
1365+ "Creating inference component with name %s for endpoint %s" ,
1366+ inference_component_name ,
1367+ endpoint_name ,
1368+ )
1369+ self .sagemaker_client .create_inference_component (** req )
1370+ if wait :
1371+ self .wait_for_inference_component (inference_component_name )
1372+ return inference_component_name
1373+
1374+ return self ._intercept_create_request (
1375+ request , submit , self .create_inference_component .__name__
1376+ )
12641377
12651378 def wait_for_inference_component (self , inference_component_name , poll = 20 ):
12661379 """Wait for an Amazon SageMaker ``Inference Component`` deployment to complete.
0 commit comments