Looking to Install and configure the AWS CLI on your Mac? This is the article for you.
In this article, I’m going to walk you through the steps to install and configure the AWS CLI on your Mac machine. Afterwards, we’ll configure your CLI by creating an IAM user in the AWS console and linking it with your CLI.
In this video we’ll be installing the V2 version (newest version) of the CLI which has access to new features and many quality of life improvements.
So lets get started.
Step 1 – Install the CLI
Open the download file and walk yourself through the wizard. Using the default options is totally fine.
If all went well, you should see a success page like below.
To confirm we installed the CLI correctly, we need to boot up our terminal to run a command. Open your terminal (hint: you can press CMD + SPACE and then type in “Terminal” to find it quickly”).
Type the command
aws into the prompt and press enter. If installed successfully, you should see an error message similar to what we see below.
Next up, we need to configure our CLI profile to give us access to our aws account.
Step 2 – Create an IAM User
In this step we’re going to head over into the AWS console and create an IAM user that has access to our AWS account. When we create our user account, AWS will provide us with two important keys: the
secret_access_key. We’ll use these two keys to configure our CLI so that we can leverage that account to interact with AWS. Note that if you delete that account or deactivate the keys, you will lose access via the CLI.
If you’re interested in learning more about how IAM works and basic concepts, you can check out my Introduction to IAM article here.
Head over to the AWS console and find the IAM section (note: you must login first). You can do this quickly by typing in IAM in the top search bar and selecting the first option like seen below.
The next screen is the landing page for the IAM section. To create our User, click on the Users text on the left hand side as seen below.
We now want to click on the Add Users button to create our initial User.
The next page is the first step of the IAM User creation wizard. Firstly, pick a username and enter it into the first text box. I’m calling mine demo-user. Note that its a good idea to pick a descriptive name for your mac if you’ll be creating many IAM users in the future.
Under the Select AWS access type make sure you select the checkbox for the top option Access Key – Programmatic Access as seen below. Failure to do so will result in IAM access keys and secret access keys not being generated, and therefore you won’t be able to configure your CLI!
Optionally, you can click the checkbox to enable Password – AWS Management Console Access. Selecting this option will provide you allow you to login to this user via the AWS console using a username and password as opposed to interacting with AWS programmatically. If this is something you want to do, make sure to select this option. Afterwards, click Next: Permissions in the bottom right.
On the next page, the first thing you’ll want to do is to select the Attach existing policies directly tab. This will allow you to select an existing IAM policy to attach to your user.
Afterwards, click the checkbox beside AdministratorAccess as seen in the image below. Selecting this option will grant your IAM user with some pretty liberal permissions that will enable you to interact with any AWS service via the CLI.
Next, click Next: Tags in the bottom right. You can skip the next screen and click Next: Review unless you intend on tagging your IAM user (useful for user organization and management.
In the final confirmation page go ahead and click on Create User to finalize the process.
The next page should be a Success page as seen below. If all went well you should be provided with the Access Key ID and Secret Access Key that we’ll be using in our terminal to configure our user. Note that you need to click the Show button under Secret Access Key to reveal the key. Keep this page open and go back to your terminal.
Step 3 – Link Your IAM User To Your CLI
In your terminal, type the command
aws configure . This should launch a pseudo-wizard which will ask a series of questions related to your setup. When it asks for AWS Access Key Id, provide it with the corresponding value outputted in the previous step. Do the same for AWS Secret Access Key with the respective value.
If prompted for a region, select the one that is geographically closest to you. For me, thats us-east-1, but us-west-1 or eu-west-1 are common ones as well. Don’t worry if you’re not sure what the ‘right’ region is for your area, you can always revise this later on.
Once completed answering the questions, you should be good to go. Give the following command a test drive to see if its working:
aws dynamodb create-table \ --table-name Music \ --attribute-definitions \ AttributeName=Artist,AttributeType=S \ AttributeName=SongTitle,AttributeType=S \ --key-schema \ AttributeName=Artist,KeyType=HASH \ AttributeName=SongTitle,KeyType=RANGE \ --provisioned-throughput \ ReadCapacityUnits=1,WriteCapacityUnits=1
You should see a success message as seen below. If it worked, congratulations! You just setup the AWS CLI on your Mac. Don’t forget to go into DynamoDB and delete your table! Now go have fun in the cloud!