1

I am using the AWS SDK for Java V2, and I want to delete a SageMaker endpoint and a SageMaker endpoint config. What is the best way to do this?

For example, I am currently first using the describeEndpoint method to see if the endpoint already exists. I do this by calling describeEndpoint and if I get an exception that includes the phrase Could not find endpoint, then I know the endpoint does not exist.

That way, I can only call the deleteEndpoint method if the endpoint already exists, as it will otherwise throw an exception. This feels like a very inelegant solution. Can we do better?

lennon310
  • 3,212

1 Answers1

1

You can use search method to search for the resource. And SearchResponse object contains hasResults() boolean method.

And in resource attribute, endpoint is one option that you could provide.

The name of the Amazon SageMaker resource to search for.

Type: String

Valid Values: TrainingJob | Experiment | ExperimentTrial | ExperimentTrialComponent | Endpoint | ModelPackage | ModelPackageGroup | Pipeline | PipelineExecution | FeatureGroup

Required: Yes

EDIT

As discussed in comment, an alternative way is to use listEndpoints in which nameContains field can be constructed with the endpoint name in the request, and call hasEndpoints() on the response.

lennon310
  • 3,212