Skip to content

Commit ff2ab43

Browse files
authored
change: ignore tags with 'aws:' prefix when creating an EndpointConfig based on an existing one (#1362)
1 parent cef7c5c commit ff2ab43

File tree

2 files changed

+41
-9
lines changed

2 files changed

+41
-9
lines changed

src/sagemaker/session.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,11 +2312,16 @@ def create_endpoint_config_from_existing(
23122312
existing_config_name (str): Name of the existing Amazon SageMaker endpoint
23132313
configuration.
23142314
new_tags(List[dict[str, str]]): Optional. The list of tags to add to the endpoint
2315-
config.
2315+
config. If not specified, the tags of the existing endpoint configuration are used.
2316+
If any of the existing tags are reserved AWS ones (i.e. begin with "aws"),
2317+
they are not carried over to the new endpoint configuration.
23162318
new_kms_key (str): The KMS key that is used to encrypt the data on the storage volume
2317-
attached to the instance hosting the endpoint.
2319+
attached to the instance hosting the endpoint (default: None). If not specified,
2320+
the KMS key of the existing endpoint configuration is used.
23182321
new_data_capture_config_dict (dict): Specifies configuration related to Endpoint data
2319-
capture for use with Amazon SageMaker Model Monitoring. Default: None.
2322+
capture for use with Amazon SageMaker Model Monitoring (default: None).
2323+
If not specified, the data capture configuration of the existing
2324+
endpoint configuration is used.
23202325
23212326
Returns:
23222327
str: Name of the endpoint point configuration created.
@@ -2328,17 +2333,14 @@ def create_endpoint_config_from_existing(
23282333
EndpointConfigName=existing_config_name
23292334
)
23302335

2331-
existing_tags = self.sagemaker_client.list_tags(
2332-
ResourceArn=existing_endpoint_config_desc["EndpointConfigArn"]
2333-
)
2334-
2335-
request_tags = new_tags or existing_tags["Tags"]
2336-
23372336
request = {
23382337
"EndpointConfigName": new_config_name,
23392338
"ProductionVariants": existing_endpoint_config_desc["ProductionVariants"],
23402339
}
23412340

2341+
request_tags = new_tags or self.list_tags(
2342+
existing_endpoint_config_desc["EndpointConfigArn"]
2343+
)
23422344
if request_tags:
23432345
request["Tags"] = request_tags
23442346

tests/unit/test_session.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1820,6 +1820,36 @@ def test_update_endpoint_non_existing_endpoint(sagemaker_session):
18201820
sagemaker_session.update_endpoint("non-existing-endpoint", "non-existing-config")
18211821

18221822

1823+
def test_create_endpoint_config_from_existing(sagemaker_session):
1824+
pvs = [sagemaker.production_variant("A", "ml.m4.xlarge")]
1825+
tags = [{"Key": "aws:cloudformation:stackname", "Value": "this-tag-should-be-ignored"}]
1826+
existing_endpoint_arn = "arn:aws:sagemaker:us-west-2:123412341234:endpoint-config/foo"
1827+
kms_key = "kms"
1828+
sagemaker_session.sagemaker_client.describe_endpoint_config.return_value = {
1829+
"Tags": tags,
1830+
"ProductionVariants": pvs,
1831+
"EndpointConfigArn": existing_endpoint_arn,
1832+
"KmsKeyId": kms_key,
1833+
}
1834+
sagemaker_session.sagemaker_client.list_tags.return_value = {"Tags": tags}
1835+
1836+
existing_endpoint_name = "foo"
1837+
new_endpoint_name = "new-foo"
1838+
sagemaker_session.create_endpoint_config_from_existing(
1839+
existing_endpoint_name, new_endpoint_name
1840+
)
1841+
1842+
sagemaker_session.sagemaker_client.describe_endpoint_config.assert_called_with(
1843+
EndpointConfigName=existing_endpoint_name
1844+
)
1845+
sagemaker_session.sagemaker_client.list_tags.assert_called_with(
1846+
ResourceArn=existing_endpoint_arn, MaxResults=50
1847+
)
1848+
sagemaker_session.sagemaker_client.create_endpoint_config.assert_called_with(
1849+
EndpointConfigName=new_endpoint_name, ProductionVariants=pvs, KmsKeyId=kms_key
1850+
)
1851+
1852+
18231853
@patch("time.sleep")
18241854
def test_wait_for_tuning_job(sleep, sagemaker_session):
18251855
hyperparameter_tuning_job_desc = {"HyperParameterTuningJobStatus": "Completed"}

0 commit comments

Comments
 (0)