AWS Logo
Menu
Q-Bits: Auto Cleanup Sagemaker Endpoints with Amazon Q Developer

Q-Bits: Auto Cleanup Sagemaker Endpoints with Amazon Q Developer

The blog post show the power of Amazon Q Developer command line being able to save hundreds by cleaning up developer Sagemaker Endpoints

Michael Kaiser
Amazon Employee
Published Mar 20, 2025
Last Modified Mar 21, 2025
Welcome to another installment of Q-Bits, our regular series showcasing cool ways Amazon employees are leveraging Amazon Q Developer. Today, we're diving into how Q Developer can assist with building a solution for autoclean up Sagemaker Endpoints.
I work with customer to help them in their cloud journey. One of those calls I another AWS colleague had commented about sometimes forgetting to delete Sagemaker endpoints and it costing hundreds to thousands of dollars for idle endpoints. That gave me an idea to see if I can build a solution that would automatically delete endpoints after a set amount of time. I wanted to try out the Amazon Q Developer CLI and see what it could do with just a couple prompts.
I started thinking I would do a config rule with RDK, to do reporting and it would auto remediate. So I loaded up a terminal and got into Q with
(the -a tells Q to auto accept running commands instead of asking me every time. I really wanted to let it go and quickly get a solution).
From here I gave it the prompt
  1. Now Q starts going through:
  2. checking if I have the correct pip packages
  3. attempting to install them (it fails because don't have a python env setup and it was relying my system python. Here if I was confirming each command I could have told it to run and jump into my pyenv environment)
  4. It pivots to creating a solution manually using AWS Serverless Application Model, sam cli.
  5. Creates the lambda python code with a function for getting the current Sagemaker endpoints, methods to check comparing the current time with the time that the endpoint was created to see if it is older than 48 hours.
  6. Creates a README.md, samconfig.toml, requirements.txt, and Amazon CloudFormation template.yaml
  7. Q wraps up by letting me all that it has done, how to run sam, and an overview of the solution.
We can see the main logic of app and at first glance it looks good. I wanted to deploy it to test it out, but I don't have sam cli installed.
But I do have and I am very familiar with writing CDK apps and using Amazon Q Developer inside of VSCode, running cdk init, and then using /dev to have it get me majority if not a complete solution for what was looking for as a solution. Again I want to see if I can just stay in the CLI without opening an IDE. So I just tell Q to convert it to a CDK app using.
With another round of it going through commands and creating folders and files, it had generated working cdk app that I could not tell the difference if I had hand created. With the main part of the cdk app being
Now I have something I can test. I changed line 52 to the following, so that I don't have to wait 48 hours for the endpoint to be deleted.
So I deploy the solution with cdk deploy and it deploys successfully! I deploy a Sagemaker Endpoint and after 1 hour the Sagemaker Endpoint is deleted with the CloudWatch Logs logging it!
With Amazon Q Developer CLI I was able to create a solution with two prompts that helps auto clean up Sagemaker endpoints in Dev accounts with only two prompts using natural language. I was truly amazed how Q has been constantly improving and is established itself as a critical tool.
 

Any opinions in this post are those of the individual author and may not reflect the opinions of AWS.

Comments