How to create EC2 instance with CLI( Command Line interface )

sreekanthkurapati
Cloudnloud Tech Community
2 min readFeb 26, 2023

Make a note of AMI ID in your region

  • If you are using personal linux other then aws EC2 . Just follow below link how to install AWS CLI

https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html

  • first config the AWS CLI and test
  • As told above just node down ami info
  1. Create an EC2 instance with the CLI:
aws ec2 run-instances --image-id ami-xxxxxx --instance-type t2.micro 

2. Let’s launch another instance with Windows AMI

aws ec2 run-instances --image-id ami-xxxxxxx  --instance-type t2.micro 

3. List all the instance and their details.

aws ec2 describe-instances

4. Describe and query specific things( List specific attributes). Let’s query IP of all the instances.

 aws ec2 describe-instances --query 'Reservations[].Instances[].PublicIpAddress'

Example : aws ec2 describe-instances — instance-ids i-04a2d6c5da4a55321 — query=Reservations[].Instances[].PublicIpAddress — region us-east-1

5. Describe and filter to show only windows Instance

aws ec2 describe-instances --query 'Reservations[].Instances[].PublicIpAddress' --filters "Name=platform,Values=windows"

6. Stop EC2

aws ec2 stop-instances --instance-ids i-0b20d7680fa0e6ba0

7. Terminate EC2

aws ec2 terminate-instances --instance-ids i-0b20d7680fa0e6ba0

Congratulations! You now know the basic AWS EC2 CLI Commands.

--

--

sreekanthkurapati
Cloudnloud Tech Community

Working as Technical Architect / Transformation Manager - Cloud & DevOps. Helping customers with Implementation & Cloud Migration - Fintech