Getting Started with AWS EC2 via CLI

Team working on a Formula 1 car during a wet race pit stop, showcasing teamwork and precision.

Provision an EC2 Instance in 3 Commands

Using the AWS CLI, you can spin up a new t3.small instance, tag it, and retrieve its public IP—all from your terminal:

# 1. Launch a new EC2 instance
INSTANCE_ID=$(aws ec2 run-instances \
  --image-id ami-0abcdef1234567890 \
  --count 1 \
  --instance-type t3.small \
  --key-name MyKeyPair \
  --query 'Instances[0].InstanceId' \
  --output text)

# 2. Tag the instance
aws ec2 create-tags \
  --resources "$INSTANCE_ID" \
  --tags Key=Name,Value="moderntechops-demo"

# 3. Get its public IP
aws ec2 describe-instances \
  --instance-ids "$INSTANCE_ID" \
  --query 'Reservations[0].Instances[0].PublicIpAddress' \
  --output text

Next Steps:

  • “SSH in: ssh -i ~/keys/MyKeyPair.pem ec2-user@$(aws ec2 describe-instances …)
  • “Configure security groups, install Nginx/Apache, and automate with user-data scripts.”

Now you’ve got a live EC2 instance in under a minute!

Spin up, tag, and retrieve your EC2 instance IP in just three AWS CLI commands.

Leave a Comment

Your email address will not be published. Required fields are marked *