AWS CLI Configure on EC2

The AWS CLI is a very useful tool to access other AWS services from your EC2 servers or even your laptop/computer. In this article we’re going to take a look at AWS CLI and set it up.

Before you start using the CLI, you need to create a user through IAM and get the Access Key ID and Secret Access Key to authenticate and authorize yourself to access those services. This user should have Programmatic Access. We have an article on creating users through IAM and giving them permissions. Be sure to go through that article if you need help creating the user.

NOTE: You can instead use roles (recommended) to give access to your EC2 instances to access other AWS services. More on that in the IAM Roles article.

Alright then, let’s get started! 🚀

Login to your AWS console and head over to Services > EC2 > Instances. Click on Connect to see the SSH connection string.

Copy the connection string and paste it in your terminal. Make sure you’re in the directory where your ssh key (.pem file) resides. Once logged into your EC2 instance enter 

aws --version

This will show you the version of AWS CLI. This basically shows you whether AWS CLI is installed or not. 

Before we start using the CLI, we have to configure it. So enter 

aws configure

As I had mentioned at the start of this article, we need the Access Key ID and Secret Access Key. If you’ve followed our IAM Create Users guide, you’ll have downloaded a csv file. This file contains the details separated by commas. The second and third items in the file are the Access Key ID and Secret Access Key respectively.

NOTE: I used Raven here but you should use Sam, as Raven only has Marketing access. Basically for this tutorial use one that has S3 access to create and read.

You can set the default region and output format if you like, I’m simply going to skip that.

If you now do 

aws s3 ls

It should show you your s3 buckets. In my case there is nothing here so it doesn’t show anything.

We can create and view the bucket to test it out.

aws s3 mb s3://bucket_name

aws s3 ls

Congratulations, Sam is now able to access the AWS services through AWS CLI! 🎉

Although, as I have mentioned before, if your purpose is to provide permissions to access AWS services, use roles instead. To set up AWS CLI on your laptop or computer, go to the AWS CLI download page and download the AWS CLI for your OS.

There’s so much more that you can do with the CLI, it’s incredibly powerful. To get a list of all the different magical commands, head over to the documentation of AWS CLI.

That’s it for taking time to read this article. Lemme know if you have any questions down below. I’ll see you around! 👋