Cheat Sheet - AWS CLI. It can also be disable with the -no-cli-pager command line option. Then # bw session is missing if command-v. 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. You can use the AWS Console or AWS CLI and the ‘ put-file’ command to add a file or submit changes to a file in a CodeCommit repository. Pull Requests Pull requests require two branches: a source branch that contains the code you want reviewed, and a destination branch, where you merge the reviewed code. The AWS Command Line Interface (CLI), on the other hand, is a unified tool to manage your AWS services. AWS CloudFormation provides a common language for you to describe and provision all the infrastructure resources in your cloud environment.
For more information see the AWS CLI version 2 installation instructions and migration guide. AWS CLI Command Reference ¶ The AWS Command Line Interface is a unified tool that provides a consistent interface for interacting with all parts of AWS.
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…
Aws Cli Commands Cheat Sheet
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
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.
Aws Cli Commands Cheat Sheet
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.
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
Launch an Instance in an Availability Zone
Spot Price History
This cheat sheet is based on the AWS Certified Developer Associate walk through by Andrew Brown. Originally I wrote down the cheat sheet from his presentation. However, I thought maybe others might have a use for the same cheat sheet in a searchable format. I really encourage you to watch his walk through over at YouTube.
- CLI - stands for Command Line Interface
- SDK - stands for Software Development Kit
- The AWS CLI lets you interact with AWS from anywhere by simply using a command line
- The AWS SDK is a set of API libraries that let you integrate AWS services into your applications
- Programmatic Access - must be enable per user via the IAM console to use CLI or SDK
- aws configure - command is used to setup your AWS credentials for the CLI
- The CLI is installed via a Python script
- Credentials get stored in a plain text file (whenever possible use roles instead of AWS credentials)
- The SDK is available for the following programming languages: C++, Go, Java, JavaScript, .NET, NodeJs, PHP, Python, Ruby
Credits
Aws Cli Commands Cheat Sheet 2019
Andrew Brown from ExamPro