DEV Community

Cover image for How to Set-Up AWS CLI: Quick Guide
Sakin Deborah
Sakin Deborah

Posted on

How to Set-Up AWS CLI: Quick Guide

Using AWS Programmatically is a good to have skill. In this first tutorial, we begin by setting up authentication on our terminal.
We will work with YAML files for automation for future use cases but wonʼt be covered here.

Terminal Set-up CLI
Open terminal, I will be using visual studio terminal on Mac.
Create folder for your project.
mkdir aws_project
cd aws_project
create gitignore file -> .gitignore

Open terminal and run the following command for mac.
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /

To get the instructions for other OS check out. https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html

Create IAM user

Navigate to your aws console and search for IAM. We will be creating an admin user to authenticate to aws from terminal.

IAM dashboard from console
Click on users in the left panel and create user

Creating users form

Use a descriptive name for the username and click next.

Creating group for user form

It is the best option to add user to a group instead of attaching policy directly. Create a group with a descriptive name as well.

Attaching policy page
Attach the AdministratorAccess policy to the group since we will use this user to create multiple resources. For future users, adopt the principle of least priviledge and provide fine-grained access to actions and resources

Then create the user

User successfully created

Click on created user and navigate to Security credentials. We will create an access key to make programmatic calls from terminal. Click on next.

Adding CLI use case to access key

Access key successfully created

Now we have created a user with required policy attached and have the secret values needed to identify from terminal. This credentials are long lived but can be rotated manually incase needed.

Configure Credentials in Terminal

Next we set the environment variables, replacing the examples shown with values retrieved from console.

export AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
export AWS_SECRET_ACCESS_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
export AWS_DEFAULT_REGION=us-west-2

To confirm that you are successfully authenticated run the command
aws sts get-caller-identity

Successfully set up credentials in terminal

To confirm if successful, list buckets present in account
aws s3 ls

Buckets present in S3 listed

Top comments (0)