User Tools

Site Tools


s3

Creating S3 IAM users

Creating an S3 IAM user with administrative privileges

  1. Create a new user
  2. Note the access key ID and secret access key (I recommend using a key ring application)
  3. Select the user in the user list
  4. Attach the policy “AmazonS3FullAccess”

Since we are going to use the CLI for the next steps, the user will not get a login password.

Getting help

To get general help on using the S3 CLI type the command below.

aws s3 help

To get help on a specific S3 command type:

aws s3 <command> help

Using S3 via the CLI

Creating an S3 bucket

To create a bucket use the following CLI command.

aws s3 mb 's3://<bucket name>'

Note that there are restrictions on bucket naming which enforce a DNS name style bucket naming.

Unless specified with the –region parameter the bucket will be created in your default region.

Deleting an S3 bucket

aws s3 rb s3://<bucket name>

Listing the buckets

To list the buckets simply use the ls command without any path.

aws s3 ls

Syncing local content with the content of an S3 bucket

S3 provides a synchronization mechanism which is similar to what rsync does.

aws s3 sync <from> <to>

Note that the order of the sync arguments is important. The second argument is the place where the content will be modified.

The example below shows how to sync the contents of the current local directory to the directory foo on the bucket mybucket.example.org.

aws s3 sync . s3://mybucket.example.org/foo

Setting a bucket life cycle

The following example demonstrates how to set a bucket policy the expires the contents of a bucket after 21 days.

BUCKET_POLICY='{"Rules":
  [
    {
      "Expiration":{"Days":21},
      "ID":"Expire after 21 days",
      "Status":"Enabled",
      "Prefix":"*"
    }
  ]
}'
aws s3api put-bucket-lifecycle --bucket file_exchange.example.org --lifecycle-configuration "$BUCKET_POLICY"

Using wildcards

If you are used to the power of Linux/Unix wildcards, you will be a little bit disappointed by the way it is done for the AWS S3 CLI.

You have to use combinations of the switches –exclude and –include to achieve similar results.

The following command will delete all files ending in .jpg from a bucket.

aws s3 rm --recursive --exclude '*' --include '*.jpg' s3://mybucket.example.org/foo

<note important>Don't forget the

--exclude

switch!</note>

At least the CLI is working case sensitive. So .JPG is not the same as .jpg.

s3.txt · Last modified: 2015/08/29 08:06 by sebastian