Copying multiple files between your local machine and CloudShell
This tutorial shows how to copy multiple files between your local machine and CloudShell.
Using the AWS CloudShell interface, you can upload or download a single file between your local machine and the shell environment at a time. To copy multiple files between CloudShell and your local machine at the same time, use one of the following options:
-
Amazon S3: Use S3 buckets as an intermediary when copying files between your local machine and CloudShell.
-
Zip files: Compress multiple files in a single zipped folder that can be uploaded or downloaded using the CloudShell interface.
Note
Because CloudShell doesn't allow incoming internet traffic, it's currently not possible
to use commands such as scp
or rsync
to copy multiple files between
local machines and the CloudShell compute environment.
Uploading and downloading multiple files using Amazon S3
This step describes how to upload and download multiple files using Amazon S3.
Prerequisites
To work with buckets and objects, you need an IAM policy that grants permissions to perform the following Amazon S3 API actions:
-
s3:CreateBucket
-
s3:PutObject
-
s3:GetObject
-
s3:ListBucket
For a complete list of Amazon S3 actions, see Actions in the Amazon Simple Storage Service API Reference.
Upload multiple files to AWS CloudShell using Amazon S3
This step describes how to upload multiple files using Amazon S3.
-
In AWS CloudShell, create an S3 bucket by running the following
s3
command:aws s3api create-bucket --bucket your-bucket-name --region us-east-1
If the call is successful, the command line displays a response from the S3 service:
{ "Location": "/your-bucket-name" }
-
Upload the files in a directory from your local machine to the bucket. Choose one of the following options to upload files:
-
AWS Management Console: Use drag-and-drop to upload files and folders to a bucket.
-
AWS CLI: With the version of the tool installed on your local machine, use the command line to upload files and folders to the bucket.
-
-
Return to the CloudShell command line and enter the following command to synchronize the directory in the shell environment with the contents of the S3 bucket:
aws s3 sync s3://your-bucket-name folder-path
Note
You can also add
--exclude "<value>"
and--include "<value>"
parameters to thesync
command to perform pattern matching to either exclude or include a particular file or object.For more information, see Use of Exclude and Include Filters in the AWS CLI Command Reference.
If the sync is successful, download messages are displayed for every file downloaded from the bucket to the directory.
Note
With the sync command, only new and updated files are recursively copied from the source directory to the destination.
Download multiple files from AWS CloudShell using Amazon S3
This step describes how to download multiple files using Amazon S3.
-
Using the AWS CloudShell command line, enter the following
aws s3
command to sync an S3 bucket with contents of the current directory in the shell environment:aws s3 sync folder-path s3://your-bucket-name
Note
You can also add
--exclude "<value>"
and--include "<value>"
parameters to thesync
command to perform pattern matching to either exclude or include a particular file or object.For more information, see Use of Exclude and Include Filters in the AWS CLI Command Reference.
If the sync is successful, upload messages are displayed for every object added to the bucket.
-
Download the contents of the bucket to your local machine. Because the Amazon S3 console doesn't support the downloading of multiple objects, you need to use the AWS CLI tool that's installed on your local machine.
From the command line of the AWS CLI tool, run the following command:
aws s3 sync s3://your-bucket-name folder-path
If the sync is successful, the command line displays a download message for each file updated or added in the destination directory.
Note
For this option, you need to have the AWS CLI tool installed on your local machine and have your credentials configured for calls to AWS services. For more information, see the AWS Command Line Interface User Guide.
Uploading and downloading multiple files using zipped folders
This step describes how to upload and download multiple files using zipped folders.
With the zip/unzip utilities, you can compress multiple files in an archive that can be treated as a single file. The utilities are pre-installed in the CloudShell compute environment.
For more information about pre-installed tools, see Development tools and shell utilities.
Upload multiple files to AWS CloudShell using zipped folders
This step describes how to upload multiple files using zipped folders.
-
On your local machine, add the files to be uploaded to a zipped folder.
-
Launch CloudShell, and then choose Actions, Upload file.
-
In the Upload file dialog box, choose Select file, and then choose the zipped folder you just created.
-
In the Upload file dialog box, choose Upload to add the selected file to the shell environment.
-
In the CloudShell command line, run the following command to unzip the contents of the zip archive to a specified directory:
unzip zipped-files.zip -d my-unzipped-folder
Download multiple files from AWS CloudShell using zipped folders
This step describes how to download multiple files using zipped folders.
-
In the CloudShell command line, running the following command to add all the files in the current directory to a zipped folder:
zip -r zipped-archive.zip *
-
Choose Actions, Download file.
-
In the Download file dialog box, enter the path for the zipped folder (
/home/cloudshell-user/zip-folder/zipped-archive.zip
, for example), and then choose Download.If the path is correct, a browser dialog offers the choice of opening the zipped folder or saving it to your local machine.
-
On your local machine, you can now unzip the contents of the downloaded zipped folder.