How to create a Powershell Script to start an EC2 instance and capture public IP?

Asked

Viewed 93 times

0

would like to create a Powershell Script that runs the following steps:

1 - Start an EC2 Instance in AWS (Windows);

2 - Wait for it to be available for remote connection. While waiting, display a waiting message for the user;

3 - Once available, get the Public IP (which will be randomized);

4 - Start Remote Desktop to capture this Instance using this IP;

Steps 1 and 4 I have already managed, but the most difficult are steps 2 and 3. I already looked here at Stackoverflow and also did not find.

If anyone has any ideas, I’d be very grateful.

Hugs

  • As for step two, I can’t help you, but on step three, take a look at this one link

  • Thank you, but the public IP address, would be the EC2 instance on Amazon Web Service, and the Script would run on the machine of the user that would capture it via Remote Desktop.

  • Every time Stops and Starts the Instance, it takes a different public IP.

  • You’re using the aws cli?

  • Yes, currently version 1.11.162

1 answer

0


  • 1

    Julio, perfect !! killed the riddle!! So was the final script:

  • 1 - aws ec2 start-instances --instance-ids i-xxxxxxxxxxxxxxxxx

  • 2 - msg * Please wait a moment while we turn on the remote computer. This may take up to 5 minutes. Thank you !!

  • 3 - aws ec2 Wait instance-status-ok --instance-ids i-xxxxxxxxxxxxxxxxx

  • 4 - $ip = aws ec2 describe-instances --query "Reservations[].Instances[].Publicipaddress" -output text

  • 5 - mstsc /v:$ip

  • Good, I don’t know much about powershell but that’s it!

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.