Command-line Access to S3

Sample Code & Libraries>Command line Access to S3
Community Contributed Software

  • Amazon Web Services provides links to these packages as a convenience for our customers, but software not authored by an "@AWS" account has not been reviewed or screened by AWS.
  • Please review this software to ensure it meets your needs before using it.

A Perl script to access S3 from the command line. Has commands to work with S3 "purely" or adopting a "filesystem metaphor". Moreover, it features a --interactive mode where you're given a shell to send multiple commands. Note: the licence is the usual Perl one, i.e. both GPL and Artistic.

Details

Submitted By: polettix
AWS Products Used: Amazon S3
Language(s): Perl
License: GNU General Public License (GPL version 2)
Source Control Access: http://repo.or.cz/w/s3.git
Created On: September 1, 2008 9:57 AM GMT
Last Updated: September 21, 2008 7:42 PM GMT
Download
The script comes with full documentation and an online help system in the interactive mode.

Usage:

s3 [--usage] [--help] [--man] [--version]

# generic options, valid for all commands
s3  [--id ] [--secret ] []

# "pure" commands
s3 acl    [--clear] [--add ] [--del ] 

s3 add    [--meta ] [--header ] [--acl ]
          [--data ] [--location ]  []

s3 copy   [--meta ] [--header ] [--acl ]
           

s3 create [--acl ] [--location ] 

s3 delete 

s3 get     []

s3 list   [--ls] [-l] [--delimiter ] [--max-keys ]
          [--marker ] []

s3 locate 

s3 meta   [--clear] [--add ] [--del ] 

s3 show   

# "filesyste-oriented" commands
s3 cat [] ...

s3 cp   [ [

s3 dir [--delimiter ] [--max-keys ]
       [--marker ] []

s3 ls  [-l] [--delimiter ] [--max-keys ]
       [--marker ] []

s3 rm   [ [ ...]]

Examples:

# list all buckets
s3 list

# create two buckets
s3 create mybucket
s3 add mybucket-x

# locate a bucket
s3 localte :mybucket

# list keys
s3 list :mybucket
s3 list :mybucket/some/prefix
s3 ls :mybucket/some/directory
s3 ls -l :mybucket/some/directory/extended-print
s3 dir :mybucket/ditto/as/above

# create a key
s3 add :mybucket/empty
s3 add :mybucket/cmdline-data --data 'Hello, World!'
s3 add :mybucket/fromfile /path/to/somefile

# get contents of one or more keys
s3 get :mybucket/key
s3 get :mybucket/tofile /path/to/destination
s3 cat :mybucket/key :mybucket-x/key-x

# make copies...
s3 copy :mybucket/source :mybucket-x/destination-copy
s3 cp /path/to/localfile :mybucket/remote
s3 cp /local/file :mybucket/remote/file /path/to/localdir
s3 cp /local/file :mybucket/remote/file :mybucket-x/path/to/remotedir/

# move stuff
s3 mv :mybucket/something /path/to/local
s3 mv /path/to/something :mybucket/remote
s3 mv /local/file :mybucket/remote/file :mybucket-x/path/to/remotedir/

# get headers
s3 show :mybucket/somekey

# get/set metadata
s3 meta :mybucket/somekey
s3 meta :mybucket/somekey --add colour:green --del taste:awful

# get/set ACL
s3 acl :mybucket
s3 acl :mybucket/somekey
s3 acl :mybucket/somekey --add any:read --del foo@example.com

# finally, delete stuff
s3 delete :mybucket/somekey
s3 delete :mybucket-x
s3 rm :mybucket

Sample interactive session:

shell$ s3
[2008/09/01 11:48:09 INFO ] s3 v0.1.0, see 's3 --man' for documentation and licencing
s3> list
2008-08-28 12:13:55.000Z http://photo.polettix.s3.amazonaws.com/
2008-08-28 07:27:17.000Z http://polettix.s3.amazonaws.com/
s3> default :polettix/
[:polettix/] s3> ls
http://polettix.s3.amazonaws.com/sviluppo/
http://polettix.s3.amazonaws.com/tmp/
[:polettix/] s3> ls -l
---------- 1 - - 0 1970-01-01 00:00:00.000Z http://polettix.s3.amazonaws.com/sviluppo/
---------- 1 - - 0 1970-01-01 00:00:00.000Z http://polettix.s3.amazonaws.com/tmp/
[:polettix/] s3> cd tmp
[:polettix/tmp/] s3> ls
http://polettix.s3.amazonaws.com/tmp/prova.txt
[:polettix/tmp/] s3> cat prova.txt
Hello, world!
[:polettix/tmp/] s3> cd ..
[:polettix/] s3> cd sviluppo/perl/s3
[:polettix/sviluppo/perl/s3/] s3> dir
---------- 1 polettix polettix 41852 2008-09-01 08:01:31.000Z http://polettix.s3.amazonaws.com/sviluppo/perl/s3/s3
[:polettix/sviluppo/perl/s3/] s3> meta s3
stat: 2049,1637677,33261,1,501,20,0,41852,1220256086,1220255961,1220255961,4096,88
[:polettix/sviluppo/perl/s3/] s3> quit
[2008/09/01 11:49:15 INFO ] exiting...
©2014, Amazon Web Services, Inc. or its affiliates. All rights reserved.