Back to Blog
Lesson 2 of the AWS: AWS Core Services for Developers course
Cloud NativeJuly 1, 20264 min read

Configuring the AWS CLI: A Beginner's Guide to Cloud Access

Master the AWS CLI configuration process. Learn how to install the tool, manage your credentials securely, and verify your connection to the AWS cloud.

AWSCLIConfigurationCredentialsDevOpsCloud Infrastructure

Previously in this course, we explored the AWS Global Infrastructure Overview: Regions and Availability Zones to understand where our resources live. Now that you know where your infrastructure resides, it’s time to learn how to control it.

The AWS Command Line Interface (CLI) is the primary tool for interacting with AWS services from your terminal. Whether you are automating deployments or inspecting resources, the AWS CLI is the "Swiss Army knife" of a DevOps engineer.

Installing the AWS CLI

Before we can interact with AWS, we need the tool installed. AWS provides unified installers for Windows, macOS, and Linux.

  1. For macOS: Use brew install awscli if you have Homebrew installed.
  2. For Windows: Download the MSI installer from the official AWS website.
  3. For Linux: Download the zip file, unzip it, and run the sudo ./aws/install script.

Once installed, verify it by running:

Bash
aws --version

If you see a version output (e.g., aws-cli/2.x.x), you are ready for configuration.

Configuring Credentials with Access Keys

The AWS CLI needs to authenticate as a user to perform actions. We do this using an AWS Access Key ID and a Secret Access Key.

Warning: Never hardcode these keys in your scripts or push them to version control.

To configure your machine, run the following command in your terminal:

Bash
aws configure

The CLI will prompt you for four pieces of information:

PromptWhat to enter
AWS Access Key IDPaste the ID provided by your IAM user creation.
AWS Secret Access KeyPaste the secret key (treat this like a password).
Default region nameUse the region you selected in our first lesson (e.g., us-east-1).
Default output formatSet this to json.

This command creates a hidden directory in your home folder (~/.aws/) containing two files: credentials and config. These files store your keys and your preferred region, respectively.

Verifying Connectivity

Now that you've configured your credentials, let's verify that your local machine can "talk" to AWS. We will use the sts (Security Token Service) command, which returns information about your identity.

Run this command:

Bash
aws sts get-caller-identity

If everything is configured correctly, you will receive a JSON response:

JSON
{
    "UserId": "AIDAX...",
    "Account": "123456789012",
    "Arn": "arn:aws:iam::123456789012:user/your-username"
}

If you see an "Access Denied" or "Invalid Client Token" error, double-check that your keys were copied correctly without any leading or trailing spaces.

Hands-on Exercise

To practice, try listing the S3 buckets in your account. Even if you haven't created any yet, running the command proves your permissions are active.

  1. Run: aws s3 ls
  2. If the command returns nothing (or a list of buckets), your configuration is functional.
  3. If you get an error, re-run aws configure and ensure your keys are valid.

Common Pitfalls

  • Expired Keys: If your keys were generated a long time ago, they might have been deactivated by an administrator. Always generate new keys if you suspect they are stale.
  • Permissions Issues: Even with valid keys, you might not have access to specific services. This is a matter of IAM Policies, which we will cover in the next lesson.
  • Multiple Profiles: If you work with multiple AWS accounts, you don't need to re-run aws configure. You can use named profiles: aws configure --profile prod. You then access them via aws s3 ls --profile prod.

Frequently Asked Questions

Q: Where are my keys stored? A: On Linux/macOS, they are in ~/.aws/credentials. On Windows, they are in C:\Users\USERNAME\.aws\credentials.

Q: Can I use environment variables instead? A: Yes. You can set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in your shell profile. Environment variables take precedence over the ~/.aws/credentials file.

Q: Is it safe to store keys in ~/.aws/? A: It is generally safe for local development, provided your machine is encrypted and secured. Never commit these files to GitHub.

Recap

We’ve successfully installed the AWS CLI, mapped your credentials to your local environment, and verified your connection with the sts service. You are now prepared to manage your infrastructure programmatically.

Up next: We will dive into IAM Users and Policies to understand how to restrict and grant permissions securely.

Similar Posts