Sub topic 9
Launching AWS CloudShell
This chapter assumes you can sign in to the Management Console and run basic shell commands. It also assumes you know what an IAM identity is. By the end you should be able to launch CloudShell, say which identity and Region it is using, and predict what survives between sessions.
What CloudShell is
AWS CloudShell is a browser-based shell that runs inside the Console. It comes with AWS CLI v2 already installed, and it needs no access keys or aws configure. Each session starts in a managed compute environment that AWS runs for you. You work in a terminal tab in your browser.
CloudShell fits when you want a quick CLI session from any machine and don't want to install or configure anything locally. It is not a general-purpose server. It has limited resources, it has a session timeout, and you can't reach it from the internet.
Launching it
You can open CloudShell in several ways from the Console:
- Select the CloudShell icon (a terminal prompt symbol) in the top navigation bar.
- Type "CloudShell" into the search box and select the service.
- Use the CloudShell link in the Console's bottom-left toolbar, where your Console shows one.
The first launch in a Region takes a short while because AWS provisions the environment. The terminal then opens with a prompt in your home directory. Later launches in the same Region start faster.
Permissions you need
Launching CloudShell is itself an IAM permission. The identity you signed in with needs access to the CloudShell service. The simplest way to grant it is the AWS managed policy AWSCloudShellFullAccess. Administrators can use a narrower custom policy to restrict features such as file upload and download.
This access is separate from what the shell can do afterward. A user can open CloudShell and still receive AccessDenied on every aws call, because CloudShell only runs commands with the permissions the user already has.
How it authenticates
CloudShell uses the credentials of the identity you are signed in to the Console with. It copies no stored keys into the environment. The shell receives temporary credentials tied to your Console session, so the CLI can start using them immediately.
Check this yourself:
aws --version
aws sts get-caller-identityThe second command returns your account ID, a user ID, and an ARN. The ARN shows who you are. For a role-based sign-in, for example through IAM Identity Center, you will see an assumed-role ARN. For an IAM user you will see a user ARN.
Two consequences follow from this model:
- You never have to run
aws configure. If you do, you create files in your home directory that can override the default behavior and confuse later sessions. - Signing out or switching identities in the Console changes what CloudShell can do. The shell is bound to the Console session, not to a long-lived key.
Region behavior
CloudShell is a regional service. Its default Region is the one currently selected in the Console's Region selector, so the shell and the Console agree on where commands run. Not every Region supports CloudShell, so check the Region list in the AWS documentation if the icon is missing.
Confirm the active Region from inside the shell:
aws configure listThe region row shows the value and where it came from. You can override it per command with --region, as you would on your own machine. This loop counts VPCs in every enabled Region from a single shell:
for r in $(aws ec2 describe-regions --query 'Regions[].RegionName' --output text); do
echo "$r: $(aws ec2 describe-vpcs --region "$r" --query 'length(Vpcs)' --output text)"
doneEach Region has its own CloudShell environment and its own home directory. If you switch the Console from us-east-1 to eu-west-1 and open CloudShell, you get a different environment. Files you saved in the first Region are not there.
The environment you get
When the shell opens, you land in a Linux environment with your home directory as the working directory. A few facts matter in practice:
- Shell: Bash is the default. Zsh and PowerShell are also available, and you can switch by typing the shell's name.
- Tabs and layouts: You can open several terminal tabs and split them to see them side by side. Each tab is a separate session in the same environment.
- Preinstalled tools: Common tools are included. These are the AWS CLI, Git, Python, Node.js, and standard Unix utilities. You can check what is present with
whichor--version. - Outbound access: The shell can reach the internet, so
pip installandgit clonework. Nothing from the internet can connect in. - Actions menu: This menu offers file upload, file download, restart, and deleting the home directory. Chapter material on file transfer covers it in detail.
CloudShell also has a command-line size cap on how much it will compute or store. It suits administration and scripts, not heavy builds.
Sessions, timeouts, and persistence
Understanding the lifecycle prevents most surprises.
- Inactivity timeout: A session ends after roughly 20 to 30 minutes with no keyboard or pointer input. Running a long command does not count as activity. A job that is silent for a long time can be cut off with the session.
- Persistent home directory: Everything under
$HOMEis kept between sessions, up to a storage limit of 1 GB per Region. - Ephemeral everything else: Files outside
$HOME, installed system packages, and running processes are lost when the session ends or the shell restarts. - Inactivity cleanup: If you do not use CloudShell in a Region for a long period (120 days), AWS deletes that Region's home directory data.
| Location or item | Survives a session ending? |
|---|---|
| Files in `$HOME` | Yes |
| Files in `/tmp` or elsewhere outside `$HOME` | No |
| Packages installed system-wide | No |
| Running background processes | No |
| Home directory in another Region | Separate storage |
To keep a tool you rely on, install it in your home directory, for example with pip install --user, and keep setup commands in a script in $HOME.
Common first-launch problems
- No CloudShell icon: The Region may not support CloudShell. Change the Region in the selector.
- Launch fails or is denied: The identity lacks CloudShell permissions. Ask an administrator to attach
AWSCloudShellFullAccessor an equivalent policy. - Commands work in the wrong place: You are in a different Region than you assumed. Run
aws configure listand compare with the Region selector. - Files missing: You are in a different Region's environment, or you saved them outside
$HOME. - Unexpected identity: Run
aws sts get-caller-identity. If the account or role is not the one you intended, switch the identity in the Console and restart CloudShell.
Exercise
You open CloudShell in us-east-1 and save a script as ~/backup.sh. Later you switch the Console to eu-west-1 and open CloudShell, but ~/backup.sh is not there. You also notice that a tool you installed with sudo is gone after a restart in us-east-1. Explain both observations and give one fix for each.
Show answer
The home directory is stored per Region, so eu-west-1 has its own empty home directory. The script still exists in us-east-1. Fix: open CloudShell in us-east-1 to use it, or copy it to the other Region, for example by downloading and uploading it. A system-wide install lives outside $HOME, which is not persistent, so it is lost on restart. Fix: install the tool under $HOME, for example with pip install --user, or keep an install script in $HOME and rerun it after each restart.
Exercise
Which two commands would you run at the start of a CloudShell session to confirm who you are acting as and which Region commands will target?
Show answer
aws sts get-caller-identity shows the account ID and ARN of the active identity. aws configure list shows the effective Region and where its value came from.