Cloudformation更改Ec2实例状态 [英] Cloudformation to Change Ec2 Instance State
问题描述
当前,我正在设计Cloudformation模板,以创建EC2实例并监视EC2实例,使用cloudwatch启用详细信息监视,并在达到指标后将实例状态更改为停止
Currently I am designing Cloudformation template to create an EC2 instance and monitor the EC2 instance, enable detail monitoring using cloudwatch and change the instance state to stop once it reached the metrics,
我能够创建一个能够启用指标的实例,但无法将实例状态更改为停止。
I am able to create a instance able to enable metrics but I am not able to change the instance state to stop.
推荐答案
如果您想在指定的 AWS :: CloudWatch :: Alarm
将资源转换为 ALARM
状态,您可以使用 Al的AlarmActions
属性
If you want to change the EC2 instance state to stop
when a specified AWS::CloudWatch::Alarm
Resouce transitions into ALARM
state, you can accomplish this using the special arn:aws:automate:region:ec2:stop
ARN in the AlarmActions
property for the alarm.
但是请注意,在此之前,您需要使用Amazon EC2或CloudWatch控制台手动创建至少一个停止,终止或重新启动警报,以创建警报。 EC2ActionsAccess
IAM角色。创建此IAM角色后,您可以直接使用CloudFormation资源创建停止,终止或重新启动警报。请参阅 PutMetricAlarm
文档以获取更多详细信息。
Note however that before this will work, you need to manually create at least one stop, terminate, or reboot alarm using the Amazon EC2 or CloudWatch console to create the EC2ActionsAccess
IAM role. After this IAM role is created, you can create stop, terminate, or reboot alarms using the CloudFormation resource directly. See the PutMetricAlarm
documentation for more details.
这篇关于Cloudformation更改Ec2实例状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!