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?

  • I think it probably does. But after doing some more research, It looks like the listEndpoints method is probably even better.
    – Plonetheus
    Jan 12, 2021 at 21:27

1 Answer 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


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.