简体   繁体   English

AWS CloudWatch 启动/停止 EC2 实例

[英]AWS CloudWatch to start/stop EC2 instances

Just looking the way to start/stop a AWS EC2 instance in case of CPU utilization increase or decrease on another EC2 instacne.只是寻找在另一个 EC2 instacne 上 CPU 利用率增加或减少的情况下启动/停止 AWS EC2 实例的方法。 I know there is service available Auto Scaling in AWS but I have a scenario where I can't take advantage of this service.我知道 AWS 中有可用的 Auto Scaling 服务,但我遇到了无法利用此服务的情况。

So just looking if it is possible or anyone can help me on this.所以只是看看是否有可能,或者任何人都可以帮助我解决这个问题。

Just detailing the concern like suppose I have 2 EC2 instance on AWS account by name EC21 and EC22.只是详细说明问题,例如假设我在 AWS 帐户上有 2 个 EC2 实例,名称为 EC21 和 EC22。 By default, EC22 instance is stopped.默认情况下,EC22 实例已停止。

Now I need to setup CloudWatch or any other service to check if load/CPU utilization increase on EC21 instance by 70% then need to start EC22 server and similarly if load decrease on EC21 instance by 30% then stop EC22 server.现在我需要设置 CloudWatch 或任何其他服务来检查 EC21 实例上的负载/CPU 利用率是否增加了 70% 然后需要启动 EC22 服务器,同样如果 EC21 实例上的负载减少 30% 然后停止 EC22 服务器。

Please advice!请指教!

When your CloudWatch alarm is triggered, it will notify an SNS topic.当您的 CloudWatch 警报被触发时,它会通知一个 SNS 主题。 You can have that SNS topic then invoke a Lambda function, which can then start your EC2 instance.您可以让该 SNS 主题然后调用 Lambda 函数,然后该函数可以启动您的 EC2 实例。

  1. Create an AWS Lambda function that starts your EC2 instance.创建一个 AWS Lambda 函数来启动您的 EC2 实例。
  2. Configure your SNS topic to invoke your Lambda function when it receives messages.将您的 SNS 主题配置为在收到消息时调用您的 Lambda 函数。 You can read about that here: Invoking Lambda functions using Amazon SNS notifications您可以在此处阅读相关信息:使用 Amazon SNS 通知调用 Lambda 函数
  3. Finally, ensure your CloudWatch alert sends messages to the SNS topic.最后,确保您的 CloudWatch 警报向 SNS 主题发送消息。

Yes this is possible for certain types of EC2 instances.是的,这适用于某些类型的 EC2 实例。 Check this detailed guide using which you can set up the triggers in your EC2 instances based on AWS Cloud Watch metrics.查看此详细指南,您可以使用该指南根据 AWS Cloud Watch 指标在 EC2 实例中设置触发器。

http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/UsingAlarmActions.html http://docs.aws.amazon.com/AmazonCloudWatch/latest/DeveloperGuide/UsingAlarmActions.html

I think your problem might fit the scenario which I'm also trying to solve now - I have some functionality which cannot be solved with Lambdas because of their low lifetime, so I need a relatively short-lived EC2 instance to accomplish the task.我认为您的问题可能适合我现在也在尝试解决的场景 - 我有一些功能无法用 Lambdas 解决,因为它们的生命周期短,所以我需要一个相对较短的 EC2 实例来完成任务。

The solution is similar to the one described by Matt, but without SNS, using AWS triggers to launch a lambda function to start the instance.该解决方案类似于 Matt 描述的解决方案,但没有 SNS,使用 AWS 触发器启动 lambda 函数来启动实例。 Added benefit is that the lambda function can itself verify whether the EC2 start is really needed.额外的好处是 lambda 函数本身可以验证是否真的需要启动 EC2。

How do I stop and start Amazon EC2 instances at regular intervals using AWS Lambda? 如何使用 AWS Lambda 定期停止和启动 Amazon EC2 实例?

Issue问题

I want to reduce my Amazon Elastic Cloud Compute (Amazon EC2) usage by stopping and starting instances at predefined times or utilization thresholds.我想通过在预定义的时间或利用率阈值停止和启动实例来减少我的 Amazon Elastic Cloud Compute (Amazon EC2) 使用量。 Can I configure AWS Lambda and Amazon CloudWatch to help me do that automatically?我可以配置 AWS Lambda 和 Amazon CloudWatch 以帮助我自动执行此操作吗?

Short Description简短说明

You can use a CloudWatch Event to trigger a Lambda function to start and stop your EC2 instances at scheduled intervals.您可以使用 CloudWatch 事件触发 Lambda 函数以按计划的时间间隔启动和停止您的 EC2 实例。

Source: AWS Knowledge Center来源: AWS 知识中心

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM