Below is the cheat sheet of AWS CLI commands for EC2.
If you are new to EC2, it’s recommended that you go through this free AWS EC2 crash course.
CLI AWS CLI is a unified tool to manage AWS services & control multiple services from the command line & automate them through. AWS Services Cheat Sheet.
- Install aws cli: pip install awscli, aws help: Load aws cli profile: aws configure: List regions: aws ec2 describe-regions: List instances: aws ec2 describe-instances: AWS CLI config files /.aws/credentials, /.aws/config: Reference: Github: awslabs/aws-shell.
- AWS CLI is an common CLI tool for managing the AWS resources. With this single tool we can manage all the aws resources sudo apt-get install -y python-dev python-pip sudo pip install awscli aws -version aws configure.
Aws Cli Cheat Sheet Pdf
If you want to know how to install AWS CLI please follow steps on this postGet help
Create instance EC2 Classic
Create instance in VPC
Start instance
Stop instance
Reboot instance
Terminate instance
View console output
Describe Instance
Create an AMI
List images(AMIs)
List security groups
Create security group
Get details of security group
Delete Security group
List key pairs
Create keypair
Import keypair
Delete keypair
Check the networking attribute
Add tags to instance
Add EBS volume
List EBS volumes
Check snapshot associated with EBS volume
Note:- All the above commands are taken from different AWS EC2 CLI reference guides and put in one place over here. Please run the commands after due diligence as we won’t be responsible for any mistakes in executing the commands and it’s consequences. If you have any concern or query feel free to contact us.
The AWS CLI is a handy and extremely powerful tool for managing resources on AWS from a local shell. In this post we will walk through the process of setting up the AWS CLI on a Linux Machine ( I use the Linux Subsystem on Windows which gives me an Ubuntu bash). Then we begin using the AWS CLI to perform administrative tasks on the environment.
What you need
- AWS IAM User with the correct permissions to administer EC2
- The Access keys of said AWS IAM User with the correct permissions
- Linux
- AWS CLI
Lets get started…
Setting Up The AWS CLI
Setup an IAM User with Permission to Administer EC2
I am always in the habit of thinking about what group a user should be in before I create the user account. In this case my new user is going to be a System Administrator with some elevated permissions. First we create a group called EC2SysAdmins and give it full access permission to EC2. Then we pull the user into that group.
- Log into the AWS Console
- Services > IAM > Groups
- Create New Group
- Group Name : EC2SysAdmins > Next Step
- Filter : AmazonEC2FullAccess > Check – AmazonEC2FullAccess > Next Step
- Review > Create Group
- You are returned to the Groups Screen
- Create a User
- Users > Add User
- User Name : EC2Admin
- Access Type : Check – Programmatic Access > Next: Permissions
- Add user to group
- Check – EC2SysAdmin > Next: Review
- Review > Create user
- You then see a Success screen listing the Access key ID and the Secret Access Key. You will need these to configure the AWS CLI later on. To make sure you have these credentials later (just in case you can not memorize long alphanumeric strings) download them.
- Click download CSV > Optionally, go to where the the file was downloaded and rename the file from credentials.csv to EC2Admin_AccessKey.csv or something a bit more fitting as you will refer to it shortly.
- Users > Add User
Install the AWS CLI Tools on Linux
In your bash shell (get bash set up on Windows 10)
sudo apt-get install awscli
Help Aws Cli Command Cheat Sheet
Configure the AWS CLI Tools on Linux
In your bash shell
aws configure
Here you need to specify:
- Your access Key ID (refer the the csv file you downloaded)
- Your Secret Access Key (refer the the csv file you downloaded)
- Your preferred default region code (for example, us-east-1). Choose a region that is closest to you for now.
- Default output format. Choose json
There may be cases where you need to reconfigure the CLI tools, such as using different account credentials. You can always reconfigure any of these items later by
just re-running the aws configure
command again.
AWS CLI Command Cheat Sheet – 101
Here is a list of commands that I’ve found helpful. I’ve made an effort to describe their uses. I hope they are helpful to you too.
List Regions and Availability Zones
Let’s first see what regions are available
You’ll get something like this.
With a list of regions in front of us, let’s take a look at which availability zones are present in a particular region. In this case lets check us-east-1.
Aws Cli Commands List
We get a text list of availability zones. TAKE NOTE: Since we already configured the region in the AWS CLI, we could just omit the --region us-east-1
parameter in the command above which would return the same list of availability zones. Include the region parameter if you have not configured a preferred default region in the AWS CLI.
Get the Name, Instance ID, IP Addresses of EC2 Instances
Sometimes you just want a human readable list of instances that you can then take action on, like quickly stopping or starting an instance based on the InstanceID.
This command is handy for a tabular list of information that you can then take action on, like quickly stopping or starting an instance based on the InstanceID.
Stop and Start Instances
Starting an instance
Stopping an instance