I have created an instance using run_instances method on EC2 client.
I want to check for whether instance is running or not.
One way to do is use describe_instances method and parse the response object.
I want to keep checking for instance state periodically till the instance state is :running. Anybody knows how to do that?
Is there any simpler way rather than parsing the response object?
(I can't use fog gem since it does not allow me to create instances in a VPC)
The v2 aws-sdk gem ships with waiters. These allow you to safely poll for a resource to enter a desired state. They have sensible limits and will stop waiting after a while raising a waiter failed error. You can do this using the resource interface of the v2 SDK or using the client interface:
# resources
ec2 = Aws::EC2::Resource.new
ec2.instance(id).wait_until_running
# client
ec2 = Aws::EC2::Client.new
ec2.wait_until(:instance_running, instance_ids:[id])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With