Reputation: 79467
I have a free tier account and I create stacks to learn how AWS works. Sometimes I forget to delete the stack and it stays on active for days, using up my free tier hours.
Can I make it so every stack I create will be deleted after a certain period of time, for example 1 day? I assume it would be either by adding something to the template or by adding some tag.
Upvotes: 0
Views: 2825
Reputation: 5259
TheeCodeDragon seems to have posted an answer with a self-deleting stack which addresses your problem. Here are some other solutions.
Scheduled AutoScaling
If your primary resources are EC2 instances, if you configure them in an autoscaling group and set a schedule for your group to scale to 0. We've done this to make instances vanish on the weekends, after 6:00 PM in our dev environment then scale back up Monday morning so we don't waste money in the dev environment. http://docs.aws.amazon.com/autoscaling/latest/userguide/schedule_time.html#create-sch-actions
Lambda (The Cron of the Cloud)
When management functionality doesn't exist out of the box, 9 out of 10 times you can write a lambda function to run on a schedule to take care of it. You can write a lambda function that runs every 'X' interval or time period and executes a delete-stack on the stack you've configured. Lambda can be set-up via CloudFormation.
Deployment Notes:
I saw your comment about the CLI not being installed by default. Even for dev I use AWS codebuild. A self-managed serverless build tool comparable to Jenkins. If you use it to run your templates the CLI is already installed. The caveat is you need to have it pull your project from source control or s3. I use codecommit because the setup is easy.
Upvotes: 3
Reputation: 125
I would do this if I go the CF way of auto deleting resources after a period of time specified.
AWS Cloud formation TTL template with auto stack deletion
but honestly, I do this in various other ways now, use a bot which has a schedule to scan my resources everyday and clean it up, because 5 years down the line, I have no more free tier credits :)
All the best!
Upvotes: 2