0

I am hitting an API using Curl command which create an EC2 instance in AWS and return the private IP of EC2 instance.

  1. newrigprivateip=$(curl -X POST -H "Content-Type:application/json" -d "'{AMI_ID:'ami-9xxxxxx'}'" $posturl)
  2. echo $newrigprivateip > $build

Now sometimes my private IP takes time to generate and because of that my script failed. Can we write the curl command in such a way that it will wait for the EC2 instance to up and wait until the private IP return.

Jagjeet
  • 1
  • 1

1 Answers1

-1

You can try retry mechanism for curl. Curl retry mechanism

This might help you out.

  • 1
    Thank you for your comment. But curl retry will create n number of EC2 instance on AWS – Jagjeet Jul 26 '21 at 15:51
  • In that case, you need to use a loop and sleep until it retrieves the ip. You can add a timeout just incase if the VM doesn’t come up. – Siva Srinivasa Rao M Jul 27 '21 at 16:44
  • I don't have great knowledge about linux shell scripting. Can you give an example, how can we use loop and wait for the ip address to return ? – Jagjeet Jul 27 '21 at 17:43