Skip to main content

Command Palette

Search for a command to run...

Launch EC2 Instance via AWS CLI

How to Launch an EC2 Instance Using AWS CLI

Published
1 min read
Launch EC2 Instance via AWS CLI
A

Infosec Poet and CAP-certified DevOps/SecOps Engineer, passionate about security, creativity, and continuous learning.

Tasks

Create an EC2 instance using AWS CLI under default VPC with the following details:

  • The name of the instance must be datacenter-ec2.

  • You can use the ami-0cd59ecaf368e5ccf AMI to launch this instance.

  • The instance type must be t2.micro.

  • Create a new RSA key pair named datacenter-kp.

  • Attach the default security group (available by default).

Steps

  1. Create a new RSA key pair named datacenter-kp:

     aws ec2 create-key-pair --key-name datacenter-kp --query 'KeyMaterial' --output text > datacenter-kp.pem
    
  2. Launch an EC2 instance with the specified AMI and instance type, and assign it the name datacenter-ec2:

     aws ec2 run-instances --image-id ami-0cd59ecaf368e5ccf --count 1 --instance-type t2.micro --key-name datacenter-kp --security-groups default --tag-specifications 'ResourceType=instance,Tags=[{Key=Name,Value=datacenter-ec2}]'
    

  3. Ensure the key pair file has the correct permissions:

     chmod 400 datacenter-kp.pem
    

    #aws #cloudcomputing #happylearning

Cloud Platforms

Part 14 of 48

This series covers cloud platforms (AWS, Azure, GCP, OCI), including certifications, labs, issues, solutions, and billing. We'll also explore on-premises solutions and hybrid cloud environments.

Up next

Create Private S3 Bucket via AWS CLI

How to Use AWS CLI for Creating Private S3 Buckets