Is there a way that Amazon Web Services EC2 instances can be self terminating? Does Amazon have anything that allows an instance to terminate itself ("Hara-Kiri") after running for more than say an hour? I could change the scripts on the running instance to do this itself, but that might fail and I don't want to edit the image, so I would like Amazon to kill the instance.
相关问题
- How to generate 12 digit unique number in redshift
- Use awslogs with kubernetes 'natively'
- JQ: Select when attribute value exists in a bash a
- Assume/switch role in aws toolkit for eclipse 2.0
- 'no SavedModel bundles found!' on tensorfl
相关文章
- Right way to deploy Rails + Puma + Postgres app to
- how many objects are returned by aws s3api list-ob
- AWS S3 in rails - how to set the s3_signature_vers
- Passthrough input to output in AWS Step Functions
- I cannot locate production log files on Elastic Be
- ImportError: cannot import name 'joblib' f
- Static IP for Auto Scale in AWS
- Step function exceeding the maximum number of char
Here is my script for Self-Terminating
If you want to assign it as Self-Stopping on Self-Terminating, you can do it one time only.
In your EC2 Console go to Instance Settings, change Shutdown Behavior to Stop.
Configure /etc/cloud/cloud.cfg, you may refer to how to run a boot script using cloud-init.
Follow answer from Eric Hammond, put the command in a file and locate it in scripts-per-boot path:
Reboot your instance, check if the script is executed:
If so, just in case you forgot to stop your instance, it will assure you that the instance will do itself termination as stopping when it has run for 55 minutes or whatever time you set in the script.
PS: For everyone want to use the Self-Stopping, one thing you should note that not all EC2 types are self recovery on restarting. I recommend to use EC2-VPC/EBS with On/Off Schedule.
To have an instance terminate itself do both of these steps:
--instance-initiated-shutdown-behavior terminate
or the equivalent on the AWS console or API call.Run
shutdown -h now
as root. On Ubuntu, you could set this up to happen in 55 minutes using:I wrote an article a while back on other options to accomplish this same "terminate in an hour" goal:
The article was originally written before
instance-initiated-shutdown-behavior
was available, but you'll find updates and other gems in the comments.You can do this
The ec2 will get its current instance id and terminate itself.
Hopefully this will work
Hope this help you !!!