LinuxCommandLibrary

aws-s3

Manage objects in Amazon S3 buckets

TLDR

Show files in a bucket

$ aws s3 ls [bucket_name]
copy

Sync files and directories from local to bucket
$ aws s3 sync [path/to/file1 path/to/file2 ...] s3://[bucket_name]
copy

Sync files and directories from bucket to local
$ aws s3 sync s3://[bucket_name] [path/to/target]
copy

Sync files and directories with exclusions
$ aws s3 sync [path/to/file1 path/to/file2 ...] s3://[bucket_name] --exclude [path/to/file] --exclude [path/to/directory]/*
copy

Remove file from bucket
$ aws s3 rm s3://[bucket]/[path/to/file]
copy

Preview changes only
$ aws s3 [any_command] --dryrun
copy

SYNOPSIS

aws s3 cp|mv|rm|ls|sync|mb|rb|presign|website|control [options]

PARAMETERS

cp
    Copies objects between S3 locations, local file system and S3, or S3 and local file system.

mv
    Moves objects between S3 locations, local file system and S3, or S3 and local file system.

rm
    Removes S3 objects.

ls
    Lists S3 objects and buckets.

sync
    Synchronizes content between an S3 bucket and a local directory.

mb
    Creates an S3 bucket.

rb
    Removes an S3 bucket.

presign
    Generates a pre-signed URL for an S3 object, allowing temporary access.

website
    Configures an S3 bucket for website hosting.

control
    Allows more granular access controls to S3 object using AWS S3 access points.

--recursive
    Applies the operation recursively to all objects in a directory or bucket (used with cp, mv, rm, sync).

--exclude
    Excludes files or objects matching a specified pattern (used with cp, mv, rm, sync).

--include
    Includes only files or objects matching a specified pattern (used with cp, mv, rm, sync).

--delete
    Deletes extraneous files from the destination during sync.

--dryrun
    Displays the operations that would be performed without actually executing them.

--acl
    Sets the Access Control List (ACL) for the S3 object.

--storage-class
    Specifies the storage class for the S3 object (e.g., STANDARD, STANDARD_IA, GLACIER).

DESCRIPTION

The aws s3 command is a crucial part of the AWS Command Line Interface (CLI), providing a unified interface to interact with Amazon Simple Storage Service (S3). It allows users to manage S3 buckets and objects directly from the Linux command line. You can use it to upload, download, delete, and copy files, synchronize directories, manage object permissions, and perform various other S3-related operations.

It uses the AWS APIs behind the scenes to execute your commands. It supports a wide variety of actions including creating and deleting buckets, listing bucket contents, managing access control lists (ACLs), and configuring bucket policies. Using the `aws s3` command requires proper AWS credentials configured within your environment either through environment variables, configuration files, or IAM roles. The command helps in automating S3 tasks, integrating S3 with other scripts and applications, and efficiently managing large amounts of data stored in S3.

CAVEATS

Requires proper AWS credentials to be configured. Ensure appropriate IAM permissions are granted to the user or role used by the CLI.

<B>EXIT CODES</B>

The aws s3 command returns various exit codes to indicate the success or failure of the operation. A zero exit code generally indicates success, while non-zero codes indicate errors. Consult AWS documentation for specific exit code meanings.

<B>CONFIGURATION</B>

AWS CLI is configured using 'aws configure' command. AWS credentials and the default region name are stored in the configuration file, usually located in '~/.aws/credentials' and '~/.aws/config'.

HISTORY

The `aws s3` command evolved as part of the AWS CLI, developed by Amazon to provide a command-line interface to interact with AWS services. It became increasingly popular as developers and system administrators sought ways to automate S3 operations and integrate them into scripting workflows.

SEE ALSO

aws(1), aws configure(1)

Copied to clipboard