AWS CLI Setup

The AWS Command Line Interface (AWS CLI) is an open source tool that enables you to interact with AWS services using commands in your command-line shell. With minimal configuration, the AWS CLI allows you to start running commands that implement functionality equivalent to that provided by the browser-based AWS Management Console from the command prompt in your terminal program:

  • Linux shells – Use common shell programs such as bash, zsh, and tcsh to run commands in Linux or macOS.
  • Windows command line – On Windows, run commands at the Windows command prompt or in PowerShell.
  • Remotely – Run commands on Amazon Elastic Compute Cloud (Amazon EC2) instances through a remote terminal program such as PuTTY or SSH, or with AWS Systems Manager.

Install AWS CLI

The installation process is straight forward. Just follow along the official AWS instructions:

https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

Afterwards test if it works by simply executing the following command:

aws --version

Your output should look like this:

ws-cli/2.5.5 Python/3.9.11 Darwin/21.4.0 exe/x86_64 prompt/off

AWS User Credentials

In AWS, an access key is a type of security credential that is associated with an identity. So, to make an API call through AWS Cli, first you will create an identity in AWS Identity and Access Management (IAM). To manage authentication and authorisation for people applications, IAM provides users, groups and roles as identities that you can manage. If you haven’t already created an user account, take a look at IAM article:

Identity and Access Management article

Just make sure that your user account has an access key for programmatic access.

Create a User Access Key

If you forgot or lost your access key but an already existing user account, here is a quick instruction how to create a new one. First, login into your AWS console and call the service IAM. On the left navigation bar click on Access management and select Users. Look for your target user account and click on it, you will be navigated to the summary page. Select the tab Security credentials. Scroll down a bit till you see the button Create access key. Execute it and write down your access key ID as well as the AWS secret access key.

IAM user create access key - image by author
IAM user create access key – image by author

Configure AWS Cli

To store your access credentials locally I recommend two different options. The first on is to create a configuration file and store them there. Therefore navigate to

cd ~/.aws

and create the configuration file, if not already done and edit it.

touch configuration && nano configuration

Then place your credentials inside the file:

[default]
aws_access_key_id = <your access id>
aws_secret_access_key = <your access key>

Another option is to let them be stored by AWS Cli directly. You have to execute the following command:

aws configure

and go through the settings, be aware that you also have to select your region of interest.

If done everything correct, you should now be able to communicate with your AWS environment through AWS Cli. You can test it for example by listing your S3 buckets:

aws s3 ls

Leave a Comment

Your email address will not be published. Required fields are marked *