@@ -825,6 +825,7 @@ def transformer(
825825 role = None ,
826826 volume_kms_key = None ,
827827 vpc_config_override = vpc_utils .VPC_CONFIG_DEFAULT ,
828+ enable_network_isolation = None ,
828829 ):
829830 """Return a ``Transformer`` that uses a SageMaker Model based on the
830831 training job. It reuses the SageMaker Session and base job name used by
@@ -863,8 +864,18 @@ def transformer(
863864 vpc_config_override (dict[str, list[str]]): Optional override for the
864865 VpcConfig set on the model.
865866 Default: use subnets and security groups from this Estimator.
867+
866868 * 'Subnets' (list[str]): List of subnet ids.
867869 * 'SecurityGroupIds' (list[str]): List of security group ids.
870+
871+ enable_network_isolation (bool): Specifies whether container will
872+ run in network isolation mode. Network isolation mode restricts
873+ the container access to outside networks (such as the internet).
874+ The container does not make any inbound or outbound network
875+ calls. If True, a channel named "code" will be created for any
876+ user entry script for inference. Also known as Internet-free mode.
877+ If not specified, this setting is taken from the estimator's
878+ current configuration.
868879 """
869880 tags = tags or self .tags
870881
@@ -876,8 +887,13 @@ def transformer(
876887 model_name = self ._current_job_name
877888 else :
878889 model_name = self .latest_training_job .name
890+ if enable_network_isolation is None :
891+ enable_network_isolation = self .enable_network_isolation ()
892+
879893 model = self .create_model (
880- vpc_config_override = vpc_config_override , model_kms_key = self .output_kms_key
894+ vpc_config_override = vpc_config_override ,
895+ model_kms_key = self .output_kms_key ,
896+ enable_network_isolation = enable_network_isolation ,
881897 )
882898
883899 # not all create_model() implementations have the same kwargs
@@ -1354,14 +1370,16 @@ def predict_wrapper(endpoint, session):
13541370
13551371 role = role or self .role
13561372
1373+ if "enable_network_isolation" not in kwargs :
1374+ kwargs ["enable_network_isolation" ] = self .enable_network_isolation ()
1375+
13571376 return Model (
13581377 self .model_data ,
13591378 image or self .train_image (),
13601379 role ,
13611380 vpc_config = self .get_vpc_config (vpc_config_override ),
13621381 sagemaker_session = self .sagemaker_session ,
13631382 predictor_cls = predictor_cls ,
1364- enable_network_isolation = self .enable_network_isolation (),
13651383 ** kwargs
13661384 )
13671385
@@ -1878,6 +1896,7 @@ def transformer(
18781896 volume_kms_key = None ,
18791897 entry_point = None ,
18801898 vpc_config_override = vpc_utils .VPC_CONFIG_DEFAULT ,
1899+ enable_network_isolation = None ,
18811900 ):
18821901 """Return a ``Transformer`` that uses a SageMaker Model based on the
18831902 training job. It reuses the SageMaker Session and base job name used by
@@ -1922,9 +1941,19 @@ def transformer(
19221941 vpc_config_override (dict[str, list[str]]): Optional override for
19231942 the VpcConfig set on the model.
19241943 Default: use subnets and security groups from this Estimator.
1944+
19251945 * 'Subnets' (list[str]): List of subnet ids.
19261946 * 'SecurityGroupIds' (list[str]): List of security group ids.
19271947
1948+ enable_network_isolation (bool): Specifies whether container will
1949+ run in network isolation mode. Network isolation mode restricts
1950+ the container access to outside networks (such as the internet).
1951+ The container does not make any inbound or outbound network
1952+ calls. If True, a channel named "code" will be created for any
1953+ user entry script for inference. Also known as Internet-free mode.
1954+ If not specified, this setting is taken from the estimator's
1955+ current configuration.
1956+
19281957 Returns:
19291958 sagemaker.transformer.Transformer: a ``Transformer`` object that can be used to start a
19301959 SageMaker Batch Transform job.
@@ -1933,12 +1962,16 @@ def transformer(
19331962 tags = tags or self .tags
19341963
19351964 if self .latest_training_job is not None :
1965+ if enable_network_isolation is None :
1966+ enable_network_isolation = self .enable_network_isolation ()
1967+
19361968 model = self .create_model (
19371969 role = role ,
19381970 model_server_workers = model_server_workers ,
19391971 entry_point = entry_point ,
19401972 vpc_config_override = vpc_config_override ,
19411973 model_kms_key = self .output_kms_key ,
1974+ enable_network_isolation = enable_network_isolation ,
19421975 )
19431976 model ._create_sagemaker_model (instance_type , tags = tags )
19441977
0 commit comments