Sub topic 10
CloudShell storage, tools, and file transfer
This chapter assumes you can launch CloudShell from the Console, that you know what a Region is, and that you are comfortable with basic shell commands such as ls, cp, and tar. You should also know that CloudShell authenticates with the credentials of the identity you used to sign in to the Console. The chapter covers what persists between sessions, which tools come preinstalled, how to move files in and out, and the limits that surprise people.
What persists and what does not
A CloudShell session runs in a temporary compute environment. Only one location is durable: your home directory, /home/cloudshell-user. Everything else is rebuilt each time the environment starts.
| Location | Persists between sessions? | Notes |
|---|---|---|
| `/home/cloudshell-user` | Yes | Persistent storage of 1 GB per Region |
| `/tmp`, `/var`, other system paths | No | Reset when the environment is recycled |
| Packages installed with `sudo` outside home | No | Must be reinstalled each session |
| Environment variables set in a session | No | Put them in a startup file in home |
Persistent storage is allocated per AWS Region. If you open CloudShell in us-east-1 and then in eu-west-1, you get two separate home directories, and a file saved in one does not appear in the other. This follows from the Region selector you met in the Console navigation chapter: CloudShell belongs to whichever Region the Console is showing.
Your persistent storage is kept after you end a session. AWS deletes it after 120 days without use in a Region. Check the current limits in the CloudShell documentation, because quotas and retention periods can change.
Checking your storage
You can see how much of the home directory you are using with standard tools.
df -h /home/cloudshell-user
du -sh /home/cloudshell-user/* 2>/dev/null | sort -h | tailThe first command shows the size and usage of the filesystem that holds your home directory. The second lists the largest items in it. If you run out of space, delete large files you no longer need. You can also delete the whole home directory from the Actions menu, which resets it. That action is irreversible, so copy out anything you want first.
Preinstalled tools
CloudShell starts with a shell and a set of tools that suit AWS work. The exact list changes over time, so confirm what you have rather than assuming.
- Shells: Bash (the default), PowerShell, and Zsh. You can switch from within a session by typing the shell name.
- AWS tooling: AWS CLI v2, and usually the AWS SAM CLI and other AWS utilities.
- Common utilities:
git,jq,curl,wget,zip,tar,vim, andnano. - Language runtimes: Python, Node.js, and often others, with
pipandnpm.
Check what is present with commands you already know:
aws --version
python3 --version
node --version
jq --version
git --versionBecause jq is available, you can post-process CLI output beyond what --query can do, for example reformatting JSON for another tool.
Installing your own tools
You have sudo access, so you can install packages. The catch is persistence. A package installed to system paths vanishes when the environment is recycled. Install tools into your home directory instead, so they survive.
mkdir -p ~/bin
python3 -m pip install --user boto3
echo 'export PATH="$HOME/bin:$PATH"' >> ~/.bashrcThe --user flag installs Python packages under ~/.local, which lives in persistent storage. Putting ~/bin on your PATH through ~/.bashrc means any binary or script you drop there is found in every new session. You can also keep a setup script in your home directory and run it at the start of a session to reinstall anything that cannot live in home.
Moving files in and out
There are two main routes: the CloudShell interface itself and Amazon S3. Use the interface for a handful of small files, and S3 for anything larger or repeated.
Upload and download through the interface
In the CloudShell window, the Actions menu has Upload file and Download file options.
- Choose Actions, then Upload file, and select a file from your computer. It lands in your home directory.
- To download, choose Actions, then Download file, and enter the path of the file, for example
reports/costs.csv.
Each transfer handles one file. For a directory, archive it first:
tar -czf results.tar.gz results/Then download results.tar.gz. Upload is limited by file size, and the interface is poor for many files, so prefer S3 for bulk work.
Transfer through Amazon S3
S3 is the reliable route because it works the same way from CloudShell and from your own computer. CloudShell already has credentials, so no aws configure step is needed. The bucket name below is a placeholder.
# From CloudShell: send a result to S3
aws s3 cp results.tar.gz s3://amzn-s3-demo-bucket/exports/
# From CloudShell: pull an input file from S3
aws s3 cp s3://amzn-s3-demo-bucket/inputs/data.csv ./data.csv
# Preview a bulk upload before running it
aws s3 sync ./site s3://amzn-s3-demo-bucket --dryrunOn your own machine you then run the matching aws s3 cp in the other direction, using your own profile. This also works for large files and for scripted transfers.
The S3 route needs permissions. The identity you used to sign in must be allowed s3:GetObject, s3:PutObject, and s3:ListBucket on the relevant bucket. A transfer that fails with AccessDenied is almost always an IAM policy issue, not a CloudShell problem.
Permissions and what CloudShell can do
CloudShell uses the permissions of your signed-in identity. It does not grant more. Access to CloudShell itself is controlled by IAM permissions such as those in the AWSCloudShellFullAccess managed policy, and administrators can narrow them, for example to block file upload and download or to restrict who can launch it.
You can confirm the identity at any time:
aws sts get-caller-identityThe output shows the account and the ARN of the identity in use. If you switched roles in the Console, CloudShell uses the role you switched to.
Network and limits to know
- Outbound access: CloudShell can reach the internet by default, so
pip,npm,curl, andgit clonework. It sits outside your VPC unless you use a VPC environment. - VPC environments: You can create a CloudShell environment attached to a VPC, so you can reach private resources such as an RDS database. These environments do not keep persistent storage, which is a trade-off to remember.
- Inactivity timeout: A session ends after about 20 to 30 minutes without keyboard input, and running processes stop. Long jobs do not belong in CloudShell. Use a service such as EC2 or AWS Batch, or run the job under
nohuponly for short tasks you can restart. - Resources: Compute and memory are modest and fixed. Do not treat it as a build server.
- Concurrent shells: You can open several tabs, but they share one environment and one home directory.
Expect these numbers to be revised. If a behavior matters to your workflow, look it up in the current documentation before you rely on it.
Common problems
- A file you saved is missing. You likely wrote it outside the home directory, or you are in a different Region than the one where you saved it. Check the Region selector first.
- A tool you installed disappeared. It went into a system path. Reinstall it into
~or add it to a setup script. - Download fails or the file cannot be found. Use a path relative to home or an absolute path, and check capitalization.
AccessDeniedon S3. Check the bucket policy and your identity's permissions withaws sts get-caller-identity, then compare with the policy.- Home storage is full. Run
du -sh ~/* | sort -h, remove large files, or archive them to S3.
Exercise
You wrote a deployment script to /opt/scripts/deploy.sh in CloudShell in us-east-1 and installed jq with sudo. The next day the script is gone and a new session in eu-west-1 shows an empty home directory. Explain both problems and give a fix for each.
Show answer
The script was saved in /opt, which is outside the persistent home directory, so it was lost when the environment was recycled. Save scripts under /home/cloudshell-user (for example ~/scripts) or keep a copy in S3 or git. The empty home directory in eu-west-1 happens because persistent storage is per Region, so that Region has its own separate home. Open CloudShell in us-east-1 to find the files, or copy them through S3. A package installed with sudo outside home also disappears, so install tools into ~ or rerun a setup script at the start of each session.
Exercise
You need to move a 3 GB directory of results from CloudShell to your laptop. Why is the Actions menu a poor choice, and what would you do instead?
Show answer
The Actions menu handles one file at a time and has size limits, and CloudShell home storage is only 1 GB, so the data may not fit there at all. Write the results directly to an S3 bucket with aws s3 cp or aws s3 sync (using --dryrun first to preview), then download them on your laptop with aws s3 cp using your own profile. Your identity needs s3:PutObject, s3:GetObject, and s3:ListBucket permissions on the bucket.