Andrea Ideas Back to catalog
What is Amazon EC2? ☁️ | AWS EC2 Explained for Beginners
Aug 28, 2026 Andrea

Mastering AWS CLI: EC2 Commands for Beginner to Pro

The AWS Command Line Interface (CLI) is a powerful tool that enables you to interact with AWS services, including EC2, from the command line. By using AWS CLI, ...

The AWS Command Line Interface (CLI) is a powerful tool that enables you to interact with AWS services, including EC2, from the command line. By using AWS CLI, you can automate tasks, manage resources, and run scripts more efficiently. This article will guide you through some of the essential EC2 operations using AWS CLI, helping you to work smarter and faster.

What is Amazon EC2? ☁️ | AWS EC2 Explained for Beginners

Before we delve into EC2 operations, ensure you have set up your AWS CLI by running `aws configure` and providing your Access Key ID, Secret Access Key, default region, and default output format. Now, let's explore EC2 management with AWS CLI.

Create And Connect To Amazon AWS Windows EC2 Instance

Launching and Managing EC2 Instances

Launching an EC2 instance is a common scenario. To launch an instance using AWS CLI, run the following command:

AWS EC2 Explained ☁️ Amazon Elastic Compute Cloud Cheat Sheet for Beginners

```bash aws ec2 run-instances --image-id ami-0123456789abcdef0 --count 1 --instance-type t2.micro --key-name MyKeyPair --security-group-ids sg-0123456789abcdef0 --subnet-id subnet-0123456789abcdef0 ```

Replace the image ID, key pair, security group ID, and subnet ID with appropriate values for your environment. The instance type and count are also customizable.

Describing Running Instances

Launching & Configuring EC2 Instances on AWS

To list all running EC2 instances, use the describe-instances command:

```bash aws ec2 describe-instances --filters 'Name=instance-state-name,Values=running' ```

This command returns a detailed view of your running instances, including instance ID, instance type, private IP, and public IP.

Stopping and Starting EC2 Instances

Primeiros Passos com AWS CLI: Tutorial Completo

Stopping an instance helps save costs when it's not in use. To stop an instance, use:

```bash aws ec2 stop-instances --instance-ids i-0123456789abcdef0 ```

Start it again later with:

```bash aws ec2 start-instances --instance-ids i-0123456789abcdef0 ```

Terminating and Creating EC2 Snapshots

the aws cli commands guide is shown with an image of a man pointing to something

Before terminating an instance, it's good practice to create a snapshot of the instance's volumes to preserve data. Use the following commands to create a snapshot and terminate the instance:

```bash aws ec2 create-snapshot --volume-id vol-0123456789abcdef0 --description 'MyVolumeSnapshot' ```

Once the snapshot is created, terminate the instance:

AWS EC2 vs Azure Virtual Machine ☁️ | Which Cloud VM Should You Choose?
the aws cli cheat sheet is shown in orange and white, with text on it
Awless tutorial: Try a smarter CLI for AWS
Upgrade Your AWS: Switching EC2 Instance Types on the Fly
practical amazon ec2, sos, kinesis, and s3
the aws basics poster is shown here
How to delete an EC2 instance (AWS Console / CLI)

```bash aws ec2 terminate-instances --instance-ids i-0123456789abcdef0 ```

Managing EC2 Snapshots

To list all snapshots, use this command:

```bash aws ec2 describe-snapshots --owner self ```

Delete a snapshot with:

```bash aws ec2 delete-snapshot --snapshot-id snap-0123456789abcdef0 ```

Working with EC2 Security Groups

Security groups control inbound and outbound traffic for your EC2 instances. To create a new security group, use:

```bash aws ec2 create-security-group --group-name my-security-group --description ' команду: Доработают ОПИСАНИЕ ' ```

To add a rule to the security group, run:

```bash aws ec2 authorize-security-group-ingress --group-id sg-0123456789abcdef0 --protocol tcp --port 22 --cidr 0.0.0.0/0 ```

This allows incoming SSH traffic from any IP address.

Describing and Deleting Security Groups

To describe all security groups, run:

```bash aws ec2 describe-security-groups ```

To delete a security group, use:

```bash aws ec2 delete-security-group --group-id sg-0123456789abcdef0 ```

Remember to remove all rules from the security group before attempting to delete it.

Embracing AWS CLI for EC2 management amplifies productivity and streamlines your workflow. As you become more comfortable with these commands, consider incorporating them into scripts and automation processes to save time and lower human error. Happy exploring!

More shots

What is Amazon EC2? ☁️ | AWS EC2 Explained for Beginners
What is Amazon EC2? ☁️ | AWS EC2 Explained for Beginners
Create And Connect To Amazon AWS Windows EC2 Instance
Create And Connect To Amazon AWS Windows EC2 Instance
AWS EC2 Explained ☁️ Amazon Elastic Compute Cloud Cheat Sheet for Beginners
AWS EC2 Explained ☁️ Amazon Elastic Compute Cloud Cheat Sheet for Beginners
Launching & Configuring EC2 Instances on AWS
Launching & Configuring EC2 Instances on AWS
Primeiros Passos com AWS CLI: Tutorial Completo
Primeiros Passos com AWS CLI: Tutorial Completo
the aws cli commands guide is shown with an image of a man pointing to something
the aws cli commands guide is shown with an image of a man pointing to something
AWS EC2 vs Azure Virtual Machine ☁️ | Which Cloud VM Should You Choose?
AWS EC2 vs Azure Virtual Machine ☁️ | Which Cloud VM Should You Choose?
the aws cli cheat sheet is shown in orange and white, with text on it
the aws cli cheat sheet is shown in orange and white, with text on it

Related topics