Your AWS lab toolkit: CLI, CloudShell and profiles

Before you run any command, double-check it

Read every command twice before you press Enter. Check the target: the system or account, the IDs, the names and the sizes. These commands are for learning and were tested in our lab, not on your system. At work, run the read-only list commands first, follow your change process, make sure a backup exists, and ask a second person to check anything that changes or deletes data. You run them at your own risk.

Nearly every check in this course runs from a terminal, so the first job is a clean AWS CLI setup on your laptop. You’ll install the AWS Command Line Interface (CLI) version 2, connect it to your lab account with aws login, and get comfortable with how profiles, Regions and output formats work.

What matters most is how you connect. For years people pasted long-lived access keys into a file on their laptop, and you’re not going to do that. You’ll use short-lived credentials that expire by themselves.

TimeYou needBy the end you can
45 minutesThe lab account from Lesson 2, a Windows laptop where you have admin rights to install software, and your root MFA device (you’ll need it one last time).Install and update the AWS CLI, sign in without access keys, work with named profiles and Regions, pick output formats, and fix the two CLI setup errors people hit most often.

What it is, in one line

An AWS CLI setup is the CLI installed on your laptop plus a profile that tells it which account, Region and credentials to use.

In Simple Words

A remote control with a battery that runs out

Using the AWS console is like walking up to the TV and pressing the buttons on it. The CLI is the remote control, which is quicker and presses the same buttons the same way every time. Old-style access keys are a remote that keeps working forever, even after someone steals it from your bag, whereas aws login gives you a remote whose battery lasts a few hours, so a lost one soon stops working on its own. A profile is just the label on the remote, like “living room TV” or “bedroom TV”, so the remote talks to the TV you picked.

Engineer's View

What the CLI really does

The AWS CLI takes a command like aws ec2 describe-instances and turns it into a signed HTTPS request to the EC2 endpoint of a Region, for example ec2.ap-south-1.amazonaws.com. Signing needs credentials, and the CLI looks for them in a fixed order: command-line options first, then environment variables (such as AWS_PROFILE), and then the profile in %USERPROFILE%\.aws\config and credentials.

aws login (CLI 2.32.0 or later) uses your normal console sign-in, MFA included, and the only thing it writes to the config file is a login_session line. The temporary credentials live in %USERPROFILE%\.aws\login\cache, refresh every 15 minutes and stop working once the principal’s session length runs out (12 hours at most). Root doesn’t need any extra permission for this, while IAM users need the SignInLocalDevelopmentAccess policy or the two signin: actions inside it.

Every command needs a Region too, which comes from --region, the AWS_REGION variable or the profile. If the Region name is wrong you won’t get an “invalid Region” message; the CLI just tries to reach an endpoint that doesn’t exist.

CloudShell is your backup plan. It’s a terminal in the browser with the CLI already installed and signed in as whoever opened the console, so it’s handy when you aren’t allowed to install software on a work laptop.

How it works, step by step

This is what goes on between typing aws login and getting your first answer back from AWS.

1Install and check the version

Install CLI version 2 using the Windows installer or winget, then make sure the version is 2.32.0 or later, because older versions don’t have aws login.

AWS CLI setup: how aws login gets short-lived credentials through the browser

2Sign in through the browser

aws login --profile saat-root opens your browser on the AWS sign-in page. You sign in the way you always do, with MFA, and the browser passes short-lived credentials back to the CLI.

3Use the profile

Any command with --profile saat-root (or with $env:AWS_PROFILE set) uses those credentials, and the CLI keeps refreshing them quietly in the background until the session ends.

4Choose how answers look

--output json is the default and works best for scripts, --output table is easy on the eyes, and --output text is easy to feed into other commands. --query trims the answer down to the fields you need before anything gets printed.

These are the three ways people hand credentials to the CLI. Only the first one leaves a permanent secret sitting on your laptop.

AWS CLI setup: access keys compared with aws login and IAM Identity Center

For this course you’ll use aws login with the root user only for this lesson’s checks. In Lesson 6 you’ll move to IAM Identity Center for daily work and delete the root profile.

✅ Checkpoint: You can explain why aws login is safer than an access key and where the CLI looks for its Region.

Hands-on lab: AWS CLI setup on Windows

Every command here runs in Windows PowerShell on your laptop. After installing, close PowerShell and open it again so it picks up the new aws command.

1Install the AWS CLI version 2

Run this in PowerShell, which installs the official package from Amazon through winget:

winget install --id Amazon.AWSCLI -e

If you don’t have winget, download AWSCLIV2.msi from AWS and run it instead, then close and reopen PowerShell.

Check the version:

cd C:\aws-lab
aws --version

You should see something like this (any version from 2.32.0 up is fine):

aws-cli/2.32.4 Python/3.13.9 Windows/11 exe/AMD64

2Sign in with aws login

Run this:

aws login --profile saat-root

Since the profile is new, the CLI asks for a Region first. It looks something like this:

No AWS region has been configured. The AWS region is the geographic location of
your AWS resources.
...
        AWS Region [us-east-1]:

Type ap-south-1 (or your nearest Region) and press Enter. Your browser opens on the AWS sign-in page, where you sign in as root with your MFA device, approve the request and wait until the browser says the CLI is ready. Then switch back to PowerShell.

3Check who you are

Run this:

aws sts get-caller-identity --profile saat-root

You should see something like this:

{
    "UserId": "123456789012",
    "Account": "123456789012",
    "Arn": "arn:aws:iam::123456789012:root"
}

4Look at what was saved

Run this:

Get-Content $env:USERPROFILE\.aws\config
Test-Path $env:USERPROFILE\.aws\credentials

You should see something like this:

[profile saat-root]
login_session = arn:aws:iam::123456789012:root
region = ap-south-1
False

The config file only holds the session name and the Region, and False tells you there’s no credentials file, so no access keys are stored on your laptop.

5Ask AWS a real question

Run this:

aws ec2 describe-availability-zones --profile saat-root --query 'AvailabilityZones[].ZoneName' --output text

You should see this:

ap-south-1a     ap-south-1b     ap-south-1c

Mumbai has three Availability Zones, and you’ll use all of them when you build the network in Lesson 8.

AWS CLI setup check: version, caller identity, config file and Mumbai Availability Zones
Example output. Your own account number and CLI version will be different.

6Try the three output formats

Run these one by one and compare the results:

aws ec2 describe-regions --profile saat-root --region-names ap-south-1 --output json
aws ec2 describe-regions --profile saat-root --region-names ap-south-1 --output table
aws ec2 describe-regions --profile saat-root --region-names ap-south-1 --query 'Regions[0].Endpoint' --output text

The last one should print exactly this:

ec2.ap-south-1.amazonaws.com

7Sign out when you finish

Run this:

aws logout --profile saat-root

This removes the cached credentials. The profile itself stays in the config file, ready for your next aws login.

✅ Checkpoint: aws --version shows 2.32.0 or later, get-caller-identity showed your account, there’s no .aws\credentials file, and Mumbai listed three zones.

Break It, Then Fix It

Most “the CLI is broken” tickets come down to one of two things: the CLI is using a profile you didn’t intend, or it’s calling a Region that doesn’t exist. Before you start, sign in again with aws login --profile saat-root.

1Break it: a profile name typo in an environment variable

Run this:

$env:AWS_PROFILE = 'saat-rot'
aws sts get-caller-identity

You’ll get this error:

The config profile (saat-rot) could not be found

An environment variable beats everything in the config file, so now every command in this PowerShell window fails, even the ones that never mention a profile. You’ll see this a lot after copying a command from a colleague.

To fix it, remove the variable (or set the correct name):

Remove-Item Env:AWS_PROFILE
aws sts get-caller-identity --profile saat-root

2Break it: a Region that doesn’t exist

Run this, with the dash missing from the Region:

aws ec2 describe-availability-zones --profile saat-root --region ap-south1

You’ll get this error:

Could not connect to the endpoint URL: "https://ec2.ap-south1.amazonaws.com/"
AWS CLI setup break lab: profile not found and a wrong Region endpoint
Both errors in one PowerShell window. The error lines will match exactly.

The CLI built a web address out of the Region name and found nothing at it. Because it looks like a network problem, people often go off checking proxies and firewalls first, when the URL in the message already shows that the Region is spelled wrong.

Correct the Region and count the zones:

aws ec2 describe-availability-zones --profile saat-root --region ap-south-1 --query 'length(AvailabilityZones)'

You should see this:

3

✅ Checkpoint: You fixed a bad AWS_PROFILE and a bad Region by reading the error message instead of reinstalling anything. Run aws logout --profile saat-root once you’re done.

This happened at work

The cleanup script that ran on the wrong account

A developer at a travel company kept two sets of access keys on her laptop, one for test and one for production. Production was the [default] profile, simply because she’d set it up first, years before. One evening she ran a script to “clean old files from the S3 bucket” and forgot to add --profile test.

The script deleted about 40,000 old booking PDFs from the production bucket, and the next morning customers opening old bookings started seeing “document not found”. Luckily versioning was turned on for the bucket, so within a few hours the team had restored the files from previous versions.

Afterwards the team changed three things. Nobody keeps long-term keys on a laptop any more; people sign in through IAM Identity Center and get a few hours of access. There’s no default profile, so a command without --profile fails instead of guessing. And the PowerShell prompt now shows the active profile in red whenever it points at production.

Common mistakes and troubleshooting

MistakeWhat you seeWhat to do
CLI version older than 2.32.0aws login isn’t a known commandReinstall the latest version 2 (winget or the MSI)
Forgetting to reopen PowerShell after installingaws is not recognizedClose and reopen the window so PATH is reloaded
A leftover AWS_PROFILE variableEvery command fails with “config profile could not be found”Remove-Item Env:AWS_PROFILE, or set the right name
Region typo“Could not connect to the endpoint URL”Read the URL in the error; fix the Region name
Long-term access keys in .aws\credentialsA secret that never expires on your laptopUse aws login now and IAM Identity Center from Lesson 6
Production as the default profileCommands without --profile hit productionHave no default profile; always name the profile

Interview questions

Click a question to open it. Each one is worded the way an interviewer might ask it, and underneath you’ll find why they ask it and one way you could answer in your own words.

Fresher level

1. When you run an AWS CLI command, how does it decide which credentials to use?

Why they ask this: They want to know you understand the credential chain, because most “wrong account” problems happen when people don’t know which source won.

How you might answer: It goes through a fixed order: command-line options first, then environment variables like AWS_PROFILE or AWS_ACCESS_KEY_ID, then the profile in the config and credentials files, and on AWS compute it falls back to the instance or container role. Whichever it finds first wins, so a leftover environment variable can quietly override my profile.

2. Can you explain in simple words what a named profile is and why you’d use one?

Why they ask this: They’re checking that you can work safely with more than one account or role, since almost every real job has at least a test and a production.

How you might answer: A named profile is a section in the .aws\config file with its own credentials source and Region, and I pick it with --profile or AWS_PROFILE. That way one laptop can talk to test and production without mixing them up.

3. The CLI can print json, table or text output. When would you pick each one?

Why they ask this: They want to see you’re at home with the CLI in daily work, where picking the right output saves time in scripts and in tickets.

How you might answer: I go for JSON when I need the full data, for a script or for jq, and table when I’m reading the results myself because it’s the easiest on the eyes. Text is tab-separated, so it’s handy for passing a value into the next command. Whichever I pick, I use --query to filter the data before it prints.

2–5 years experience

4. A colleague says every CLI command fails with “Could not connect to the endpoint URL”. How would you help them?

Why they ask this: They’re looking for a methodical approach that starts from the error message, because good engineers read the error before they start guessing.

How you might answer: I’d read the URL in the message first, because a wrong Region name is the usual cause, and check --region, AWS_REGION and the Region in their profile. If the Region turns out fine, I’d look at the proxy settings and whether the network allows outbound HTTPS to amazonaws.com.

5. Why would you tell a teammate to use aws login instead of aws configure with access keys?

Why they ask this: They want to know you understand the risk of long-term keys and why temporary credentials are better. It’s one of the most common security gaps they see.

How you might answer: aws configure keeps a long-term key in plain text until somebody deletes it. aws login uses the console sign-in with MFA and only stores short-lived credentials, which refresh every 15 minutes and stop after 12 hours at most, so a copied file isn’t worth much to anyone.

6. Say you’re worried someone on the team will run a command against production by mistake. What would you put in place?

Why they ask this: They want to see you think about safe defaults instead of relying on people to be careful, because good engineers have accidents too.

How you might answer: I’d get rid of the default profile and keep production in its own account. People would get read-only roles by default and switch to an elevated role only when they need it. I’d also make the shell prompt show the active profile, and push changes through reviewed code rather than one-off scripts.

Senior level

7. Your company has 200 IAM users with access keys on laptops. How would you move everyone off them without breaking their work?

Why they ask this: They want to see you can plan a real migration in stages and that you think about the people affected as well as the end state.

How you might answer: I’d begin with the credential report to find every key and when it was last used. Then I’d set up IAM Identity Center with groups and permission sets and move teams across one at a time with aws sso login. Unused keys get disabled first and the rest deleted after a short grace period. Keys only stay for systems that can’t use roles, and those get rotated.

8. Everyone has a local CLI now. When would you still reach for CloudShell?

Why they ask this: They’re looking for judgement about tools rather than loyalty to one, and knowing where each fits shows real experience.

How you might answer: When a laptop is locked down and I can’t install software, or during an incident when I need a quick check from any browser, CloudShell is great. It’s also useful when I want to be certain I’m running as the same identity as my console session. For everyday scripting, though, I’d rather use my local CLI with my own tools and history.

Quick quiz

Q1. Which minimum AWS CLI version supports aws login?

  1. 1.29
  2. 2.0.0
  3. 2.32.0
  4. Any version
Show answer

C: aws login arrived in CLI 2.32.0, and older versions don’t recognise the command.

Q2. After aws login, what does .aws\config contain for the profile?

  1. An access key and secret key
  2. A login_session line and the Region
  3. Your password
  4. Nothing
Show answer

B: only the session name and Region get saved, while the temporary credentials sit in the login cache.

Q3. Every command fails with “The config profile (saat-rot) could not be found”. What is the quickest fix?

  1. Reinstall the CLI
  2. Remove or correct the AWS_PROFILE variable
  3. Create a new account
  4. Change the output format
Show answer

B: a wrong AWS_PROFILE environment variable affects every command run in that window.

Q4. What does “Could not connect to the endpoint URL: https://ec2.ap-south1.amazonaws.com/” most likely mean?

  1. EC2 is down
  2. The Region name is wrong
  3. You need MFA
  4. The CLI is too new
Show answer

B: the CLI builds the endpoint from the Region name, and ap-south1 isn’t a Region.

Q5. How many Availability Zones does the Mumbai Region (ap-south-1) list?

  1. 1
  2. 2
  3. 3
  4. 6
Show answer

C: describe-availability-zones lists ap-south-1a, ap-south-1b and ap-south-1c.

Quick recap

  • Install AWS CLI version 2 (2.32.0 or later) with winget or the MSI, and reopen PowerShell afterwards.
  • aws login signs in through the browser with MFA and keeps only short-lived credentials (refresh every 15 minutes, 12 hours at most).
  • A profile stores the session and the Region. AWS_PROFILE overrides the config file, so one typo there breaks every command.
  • A wrong Region shows up as “Could not connect to the endpoint URL”, and the URL in the message tells you what’s wrong.
  • Use --output and --query to get just the answer you need, and run aws logout to delete the cached credentials.

Next lesson

Lesson 4: Regions, Availability Zones and AWS billing → Next up is how Regions and zones affect speed, failure and cost, plus a cleanup script you’ll run after every lab.

Further reading: AWS CLI setup

If you want to go further with AWS CLI setup, the official guides are Installing or updating the AWS CLI and Login for AWS local development using console credentials. The full plan for this course is on the AWS Cloud Administration course page.

Scroll to Top

This website uses cookies

We use a few cookies to keep this site working. If you allow it, we also use Google Analytics to count visits so we can improve our lessons. You can accept all, deny the optional ones, or choose what to allow.