Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create EC2 instance without starting

I would like to create some EC2 instance, but before it starts do some stuff using instance ID generated for this instance. Is there any option in aws ec2 run-instances or another aws ec2 command for creating an AWS EC2 instance without starting it? A workaround would be generating UUID to tag this instance and associate this UUID instead of instance ID, or stopping just after run instance, but I would prefer some smarter solution.

like image 946
pt12lol Avatar asked May 11 '17 06:05

pt12lol


People also ask

How can I create AMI without reboot?

For the No reboot setting, you can select the Enable check box to prevent Amazon EC2 from shutting down and rebooting the instance. If you choose to enable No reboot, we can't guarantee the file system integrity of the created image.

Can we launch instance without Keypair?

Windows: Admin password (for which private key is required to decrypt) is not needed because some other user is an admin. Caution: If you launch an instance with no keypair and don't have any of the above mentined ways to access the instance, you have to relaunch the instance with a keypair.


2 Answers

There is no option under EC2 to create an instance without starting it. Once you create an instance it will automatically will move from pending to running state

Docs - http://docs.aws.amazon.com/cli/latest/reference/ec2/run-instances.html

like image 69
Colwin Avatar answered Sep 18 '22 13:09

Colwin


So as I was telling to @pt12lol in the comments, this is exactly what userdata is for.

From Amazon's documentation:

When you launch an instance in Amazon EC2, you have the option of passing user data to the instance that can be used to perform common automated configuration tasks and even run scripts after the instance starts. You can pass two types of user data to Amazon EC2: shell scripts and cloud-init directives. You can also pass this data into the launch wizard as plain text, as a file (this is useful for launching instances via the command line tools), or as base64-encoded text (for API calls).

User-datas can be passed to the instance at creation time, for instance using the --user-data flag in the aws cli or the Userdata text box in AWS console.

like image 31
iMil Avatar answered Sep 17 '22 13:09

iMil