Uploading Objects to S3
This guide explains how to upload files (or “objects”) to your Amazon S3 bucket. You will learn how to use the AWS Command Line Interface (CLI) to upload files, which is a common and efficient method for managing your S3 resources.
Prerequisites
Section titled “Prerequisites”Before you begin, you will need:
- An active University of Oregon AWS account.
- An existing S3 bucket. You can create one by following our Using Amazon S3 for Object Storage guide.
- The AWS CLI installed and configured with your UO account credentials.
Using the AWS CLI to Upload Objects
Section titled “Using the AWS CLI to Upload Objects”The AWS CLI provides a simple command, aws s3 cp, to copy files to and from S3. It works much like the cp command on Linux or macOS.
Uploading a Single File
Section titled “Uploading a Single File”To upload a single file to your S3 bucket, use the following command. Replace my-local-file.txt with the path to your local file and s3://your-bucket-name with the URI of your S3 bucket.
aws s3 cp my-local-file.txt s3://your-bucket-name/Uploading a Directory
Section titled “Uploading a Directory”To upload an entire directory, you can use the --recursive flag. This will copy all files and subdirectories from the local path to the S3 bucket.
aws s3 cp ./my-local-directory/ s3://your-bucket-name/ --recursiveCode Explanation
Section titled “Code Explanation”aws s3 cp: This is the AWS CLI command for copying objects to, from, and between S3 buckets.my-local-file.txt: This is the path to the local file you want to upload.s3://your-bucket-name/: This is the destination S3 bucket URI. Thes3://prefix is required.--recursive: This flag is used to copy an entire directory and its contents.
Next Steps
Section titled “Next Steps”Now that you know how to upload objects to S3, you can start using it to store your data. Here are some next steps you might consider:
- Learn how to set up S3 Bucket Policies for fine-grained access control.
- Explore how to use S3 with other AWS services, such as EC2 or Lambda.