如果基础设施在一段时间内未使用,如何在 aws 中自动触发 terraform destroy?
我希望我的基础设施在一段时间内未使用时自动销毁,例如。 1小时。
我使用 S3 后端来实现 terraform,这意味着我可以从任何地方应用或销毁。我想知道是否一个好的解决方案是在我的 terraform 脚本中为创建的负载均衡器创建一个 cloudwatch 指标。然后创建一个 lambda 函数,该函数不断检查该指标,如果负载均衡器一小时内没有任何传入数据,则执行 terraform 销毁?
I want my infrastructure to be destroyed automatically if it has not been used for a certain amount of time, eg. 1 hour.
I am using S3 backend for terraform meaning I can apply or destroy from anywhere. I'm wondering if a good solution is to create an cloudwatch metric in my terraform script for the load balancer created. Then create a lambda function which keep checking this metric and do a terraform destroy if the load balancer has not had any incoming data for an hour?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,你可以这样做。关键是,AWS 不会监控您的使用情况,除了 AWS Trusted Advisor< 中的少数情况。 /a> 可以检测未使用的实例或负载均衡器。
因此,您必须为此开发自己的解决方案,而带有 cloudwatch 的 lambda 是实现此目的的好方法。当然,问题是,当您获得指标后,您将如何启动平衡器。如果没有 LB,将不会生成任何新指标来指示您有新请求。
Yes, you can do that. The point is that AWS does not monitor your usage, except few cases in AWS Trusted Advisor which can detect not-utilized instances or load balancers.
So you would have to develop your own solution for that, and lambda with cloudwatch is a good way of doing this. Off course the issue is, how would you start the balancer later on when you get the metrics. Without LB, there won't be any new metrics generated to indicate that you have new requests.