AWS CLI is a powerful tool that allows you to interact with AWS services from the command line. In this blog post, I will show you how to install and configure AWS CLI on your machine, and how to use some of the common commands to manage your AWS resources.
To install AWS CLI, you need to have Python 3.6 or higher installed on your system. You can check your Python version by running python --version
in your terminal. If you don’t have Python installed, you can download it from https://www.python.org/downloads/.
Once you have Python installed, you can use the pip package manager to install AWS CLI. Pip is a tool that lets you install and manage Python packages. To install AWS CLI using pip, run the following command in your terminal:
pip install awscli
This will download and install the latest version of AWS CLI on your machine. You can verify that the installation was successful by running aws --version
. You should see something like this:
aws-cli/2.2.49 Python/3.9.7 Linux/5.4.0-89-generic botocore/2.0.0
Now that you have AWS CLI installed, you need to configure it with your AWS credentials and region. Your credentials are the access key ID and secret access key that identify you as an AWS user. You can create and manage your credentials in the IAM console.
To configure AWS CLI with your credentials and region, run the following command in your terminal:
aws configure
This will prompt you to enter your access key ID, secret access key, default region, and default output format. For example:
AWS Access Key ID [None]: AKIAIOSFODNN7EXAMPLE
AWS Secret Access Key [None]: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
Default region name [None]: us-east-1
Default output format [None]: json
You can leave the default output format as json, or choose another format such as text or table. The output format determines how the results of your commands are displayed in the terminal.
Once you have configured AWS CLI, you are ready to use it to interact with AWS services. You can run `aws help` to see a list of available commands and options. For example, you can run `aws s3 help` to see the commands for working with Amazon S3, a storage service.
One of the most common commands is `aws s3 ls`, which lists the buckets (containers for objects) in your account. For example:
$ aws s3 ls
2021-10-31 12:34:56 my-bucket-1
2021-10-31 12:35:12 my-bucket-2
You can also use `aws s3 ls` to list the objects (files) in a bucket by specifying the bucket name as an argument. For example:
$ aws s3 ls my-bucket-1
2021-10-31 12:36:23 12345 file1.txt
2021-10-31 12:37:45 67890 file2.jpg
```
You can use other commands such as aws s3 cp
to copy objects between buckets or between local and remote locations, aws s3 rm
to delete objects, aws s3 sync
to synchronize directories, and so on.
In this blog post, I have shown you how to install and configure AWS CLI on your machine, and how to use some of the common commands to manage your AWS resources. AWS CLI is a powerful tool that can help you automate tasks and simplify workflows. To learn more about AWS CLI, you can visit the official documentation at https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html.