forked from timkay/aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
howto.html
710 lines (704 loc) · 39.8 KB
/
howto.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
<html>
<head>
<title>aws - HowTo - simple access to Amazon EC2 and S3</title>
<meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=1;"/>
<style>
@import url("../style.css");
</style>
</head>
<body>
<h2 style="background-color: #082466; color: #fff"> aws - HowTo - simple access to Amazon EC2 and S3</h2>
<p>
<img align=absmiddle src=http://s3.timkay.com/timeyes.gif> <a href=../>timkay.com</a> » <a href=../tools/>tools</a> » <a href=.>aws</a> » how to
<p>
aws is a command-line tool that gives you easy access to Amazon EC2
and Amazon S3. aws is designed to be simple to install and simple to
use.
<p>
This document shows you how to do various tasks using "aws".
<ol>
<li>
<b>Get started with EC2.</b>
<p>
<ol>
<li>Create a key pair. <code>aws addkey KN</code>, where <code>KN</code> is the name of the keypair.</li>
<li>Create private key file. Copy everything between (and including) <code>-----BEGIN ...</code> and <code>----END ...</code> to a file <code>~/.ssh/KN.key</code>. Then <code>chmod og-rwx ~/.ssh/KN.key</code>.</li>
<li>Create a security group. <code>aws addgrp GN -d DESC</code>, where <code>GN</code> is the name of the group, and <code>DESC</code> is a description.</li>
<li>Allow ssh. <code>aws auth GN -P tcp -p 22 -s 0.0.0.0/0</code> to allow any host to access port 22 (ssh).</li>
<li>Run an instance. <code>aws run IMAGE -k KN -g GN</code>, where <code>IMAGE</code> is an image chosen from <code>aws dim -o amazon</code>.</li>
<li>Wait. Run <code>aws din</code> repeatedly, until you see the instance is running, and you see <code>dnsName</code>.</li>
<li>Access the instance. <code>ssh -i ~/.ssh/KN.key root@DNSNAME</code>.</li>
</ol>
<p>
<blockquote><xmp>$ aws addkey key1
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEArtdamr7NtT/qQU3fVlPD8MOsZ8HME8PUCeJSQiT8DqKgIdAM4S5Q7txHtfUx
ONw25VhSy ... CP+kivmWmfhS
j9Zhyi9WQWtT7irrrBjpeWkzTi7/bIXPuqFyO7fHdWGwEqtrEb4akzHziY/sQnwrvvrWwQ==
-----END RSA PRIVATE KEY-----
(copy-paste to ~/.ssh/key1.key)
$ chmod og-rwx ~/.ssh/key1.key
$ aws addgrp sec1 -d "Security Group 1"
$ aws auth sec1 -P tcp -p 22 -s 0.0.0.0/0
$ aws dgrp sec1
+--------------+-----------+------------------+------------+----------+--------+------------------------+
| ownerId | groupName | groupDescription | ipProtocol | fromPort | toPort | ipRanges |
+--------------+-----------+------------------+------------+----------+--------+------------------------+
| 262088988105 | sec1 | Security Group 1 | | | | |
| | | | tcp | 22 | 22 | item= cidrIp=0.0.0.0/0 |
+--------------+-----------+------------------+------------+----------+--------+------------------------+
$ aws run -g sec1 -k key1
$ aws din |cut -b -150
(repeat until you see dnsName)
+------------+--------------+----------------------+-------------------------------------------+--------------------------------------------+---------
| instanceId | imageId | instanceState | privateDnsName | dnsName | keyName
+------------+--------------+----------------------+-------------------------------------------+--------------------------------------------+---------
| i-df72c1b6 | ami-23b6534a | code=16 name=running | domU-12-31-39-00-51-01.compute-1.internal | ec2-75-101-208-212.compute-1.amazonaws.com | key1
+------------+--------------+----------------------+-------------------------------------------+--------------------------------------------+---------
$ ssh -i ~/.ssh/key1.key ec2-75-101-208-212.compute-1.amazonaws.com.
The authenticity of host 'ec2-75-101-208-212.compute-1.amazonaws.com. (75.101.208.212)' can't be established.
RSA key fingerprint is 23:82:0f:f6:12:f2:6e:61:fb:3d:50:7c:23:61:82:66.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'ec2-75-101-208-212.compute-1.amazonaws.com.,75.101.208.212' (RSA) to the list of known hosts.
[email protected].'s password:
bash-3.00$ ssh -i ~/.ssh/key1.key [email protected].
__| __|_ ) Rev: 2
_| ( /
___|\___|___|
Welcome to an EC2 Public Image
:-)
#</xmp></blockquote>
<p>
</li>
<li>
<b>Use the CopyObject function to copy an Amazon S3 object without having to download it first.</b>
<p>
The new "copy" (v1.13) command works like this:
<blockquote><code>aws copy test681/tim2.jpg tim.jpg</blockquote>
to copy the object on the right to the object on the left. It is equivalent to the following, which has been available in previous versions:
<blockquote><code>aws put "x-amz-copy-source: /test681/tim.jpg" test681/tim2.jpg /dev/null</code></blockquote>
You can use all the documented COPY Object features, including conditional copying and replacing the metadata. See the S3 documentation: <a href=http://docs.amazonwebservices.com/AmazonS3/2006-03-01/index.html?RESTObjectCOPY.html>REST COPY Object</a>.
<p>
Remember that meta-data is copied by default (see the REPLACE directive), but that the acl isn't copied. You can copy an object and keep it readable this way:
<blockquote><code>aws copy "x-amz-acl: public-read" test681/tim2.jpg tim.jpg</code></blockquote>
<p>
If your source and target names are not fully specificied, the following processing happens:
<p>
<table style="font-face: courier-new">
<tr><th>command</th><th>effect</th><th>comment</th></tr>
<tr><td>aws copy target source</td><td>target/source <-- target/source</td><td>nonsense, unless you use the REPLACE directive to replace metadata</td></tr>
<tr><td>aws copy target /bucket/source</td><td>target/source <-- /bucket/source </td><td>target ends with / (or contains no /), so copy filename to target</td></tr>
<tr><td>aws copy target/dest source</td><td>target/dest <-- /target/source</td><td>source doesn't start with /, so copy object to source</td></tr>
<tr><td>aws copy target/dest /bucket/source </td><td>target/dest <-- /bucket/source</td><td>names are absolute; nothing to combine</td></tr>
</table>
<p>
</li>
<li>
<b>How to run "aws" on Windows Vista</b>
<p>Running AWS on Windows Vista
<br>From: Roger <******@gmail.com>
<br>Date: Tue, Jul 8, 2008 at 8:56 PM
<br>To: [email protected]
<p>
Hi Tim,
<p>
I thought you might like to know I got AWS working on Windows Vista. I basically followed your Windows Download and Configuration steps. I got the following error when I tried to run curl.
<p>
The application has failed to start because its side-by-side configuration is incorrect.
<p>
I looked in the Windows Logs/Applications, and found this error message:
<p>
Activation context generation failed for "C:\S3\curl.exe". Dependent Assembly Microsoft.VC90.CRT,processorArchitecture="x86",publicKeyToken="1fc8b3b9a1e18e3b",type="win32",version="9.0.21022.8" could not be found. Please use sxstrace.exe for detailed diagnosis.
<p>
It turns out in XP and Vista, Microsoft has implemented something called "SxS.com with mainifest" to overcome "dll-hell", so that programs can run "side-by-side". Long story short, after researching around a bit, I found that the "VC90.CRT" object was missing, and that going to the website listed below, and downloading and running "vcredist_x86.exe" installed the missing "VC90.CRT" object. After running this program, AWS now runs on Vista.
<p>
Brief Description
<p>
The Microsoft Visual C++ 2008 Redistributable Package (x86) installs runtime components of Visual C++ Libraries required to run applications developed with Visual C++ on a computer that does not have Visual C++ 2008 installed.
<p>
File Name: vcredist_x86.exe
<p>
http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en
<p>
Hope that helps any of your "Vista-istas". FWIW, I am running Vista Home Premium on a 32-bit Dell Inspirion 530 with Intel Core 2 Duo processor.
<br>Regards,
<br>Roger Matthews</xmp>
<p>
</li>
<li>
<b>How do I put multiple files to S3?</b>
<p>
The current "aws" stays pretty faithful to the features provided by
the original Amazon implementation. I am trying to figure out how I
want to extend it to handle multiple files and other things.
<p>
To do what you want, you can, for example, use a single line of Perl.
<blockquote><code>
perl -e 'system("aws put bucketname/ $_") for @ARGV' *.gif *.jpg *.png
</code></blockquote>
That's all there is to it. Why does it work?
<p>
"-e" tells perl that the next argument on the command line is the script. In this case, the script is
<blockquote><code>
system("aws put bucketname/ $_") for @ARGV
</code></blockquote>
which tells Perl to construct the command "aws put bucketname/ $_" for
each command line argument (which are stored in the array "@ARGV"),
and run it as a linux command. The special variable "$_" gets
replaced by the current command line argument. Thus,
<blockquote><code>
perl -e 'system("aws put bucketname/ $_") for @ARGV' my name is Tim
</code></blockquote>
would run the sequence of linux commands:
<blockquote><xmp>aws put bucketname/ my
aws put bucketname/ name
aws put bucketname/ is
aws put bucketname/ Tim
</xmp></blockquote>
If that doesn't make sense, then you should think about it more. If it still doesn't make sense, then I need to apologize, as it's a bit on the sophisticated side for many users.
<p>
One more point: if you specify the target as a bucket name and no file name (or if the target ends in "/"), then aws uses the filename as both the source filename and also as the target object name. Thus, the files "my", "name", "is", and "Tim" all get uploaded to S3 as bucketname/my, bucketname/name, bucketname/is, and bucketname/Tim.
<p>
Also, see the entry below about filenames with funny characters interacting with the shell.
<p>
</li>
<li>
<b>How do I do such scripting when my file names have funny characters in them?</b>
<p>
If your files have funny characters in them, such as apostrophe ('), then you should use Perl's system() function in a way that doesn't involve the shell. Here are examples:
<blockquote><xmp>$ perl -e 'do {print "putting $_\n"; system (qw(aws put test681), $_)} for @ARGV' ascii/*.txt
putting ascii/char_20_ .txt
putting ascii/char_21_!.txt
putting ascii/char_22_".txt
putting ascii/char_23_#.txt
putting ascii/char_24_$.txt
putting ascii/char_25_%.txt
putting ascii/char_26_&.txt
putting ascii/char_27_'.txt
putting ascii/char_28_(.txt
putting ascii/char_29_).txt
putting ascii/char_2a_*.txt
putting ascii/char_2b_+.txt
putting ascii/char_2c_,.txt
putting ascii/char_2d_-.txt
putting ascii/char_2e_..txt
putting ascii/char_30_0.txt
$ aws ls -l test681/ascii/
-rw------- 1 timkay681 2 2009-04-19 00:57:28 ascii/char_20_ .txt
-rw------- 1 timkay681 2 2009-04-19 00:57:29 ascii/char_21_!.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:29 ascii/char_22_".txt
-rw------- 1 timkay681 2 2009-04-19 00:57:29 ascii/char_23_#.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:30 ascii/char_24_$.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:30 ascii/char_25_%.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:30 ascii/char_26_&.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:31 ascii/char_27_'.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:31 ascii/char_28_(.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:31 ascii/char_29_).txt
-rw------- 1 timkay681 2 2009-04-19 00:57:31 ascii/char_2a_*.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:32 ascii/char_2b_+.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:32 ascii/char_2c_,.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:32 ascii/char_2d_-.txt
-rw------- 1 timkay681 2 2009-04-19 00:57:33 ascii/char_2e_..txt
-rw------- 1 timkay681 2 2009-04-19 00:57:33 ascii/char_30_0.txt
</xmp></blockquote>
This command runs the code in the <code>do {...} for @ARGV</code> once for each file <code>ascii/*.txt</code>. For each file, the text "putting" is displayed, followed by the filename, and then the <code>aws</code> is run with arguments "put", "test681", and the filename. The list form of <code>system()</code> runs <code>aws</code> directly, without involving the shell. Thus, we avoid the shell mucking with special characters.
<blockquote><xmp>$ aws ls test681/ascii/ --exec='print "copying $key...\n"; system qw(aws copy test682), "/$bucket/$key"'
copying ascii/char_20_ .txt...
+--------------------------+
| LastModified |
+--------------------------+
| 2009-04-19T01:05:52.000Z |
+--------------------------+
...
copying ascii/char_30_0.txt...
+--------------------------+
| LastModified |
+--------------------------+
| 2009-04-19T01:05:57.000Z |
+--------------------------+
</xmp></blockquote>
<p>
</li>
<li>
<b>How do I remove files older than 6 days old?</b>
<p>
The old way:
<blockquote><code>
$ perl -ne 'chop; split(/\t/); system("aws rm test681/$_[2]") if $_[1] lt "2008-06"' 'aws ls --simple test681|'
</code></blockquote>
As cool as that is, the new <code>--exec</code> parameter makes it much easier. You can use <code>--exec</code>, for example, to list the contents of all your buckets:
<blockquote><code>aws ls --exec='system("aws ls $key")'</code></blockquote>.
To remove files older than 6 days old:
<blockquote><code>
aws ls test681 --exec='system("aws rm test681/$key") if $mod lt "2008-06"'
</code></blockquote>
The --exec parameter lets you specify arbitrary Perl code that is to
be run once for each result of the "ls" command. It works for the
list of objects within a bucket, and it works for the list of buckets.
<p>
The available variables are $size (of file in bytes), $mod (modification date), and $key (name of file). To be compatible with the old way, $_ and @_ are also available.
<p>
Please be careful, so that you don't delete files that you need.
(Obviously, I take no responsibility for "aws".) I'll suggest that
you can copy the S3 object to a "trash" bucket before you delete the
original.
<p>
</li>
<li>
<b>View and Modify S3 Sub-resources (acl, bittorrent, location, and logging)</b>
<blockquote><xmp>$ aws get test681?acl
+-------------------------------------------------------------------------------------------+--------------+
| Grantee | Permission |
+-------------------------------------------------------------------------------------------+--------------+
| ID=c1438ce900acb0db547b3708dc29ca60370d8174ee55305050d2990dcf27109c DisplayName=timkay681 | FULL_CONTROL |
+-------------------------------------------------------------------------------------------+--------------+
$ aws --xml get test681?acl
<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>c1438ce900acb0db547b3708dc29ca60370d8174ee55305050d2990dcf27109c</ID>
<DisplayName>timkay681</DisplayName>
</Owner>
<AccessControlList>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
<ID>c1438ce900acb0db547b3708dc29ca60370d8174ee55305050d2990dcf27109c</ID>
<DisplayName>timkay681</DisplayName>
</Grantee>
<Permission>FULL_CONTROL</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>
$ aws --xml get test681?acl >acl.xml
</xmp></blockquote>
Now edit the acl.xml file, and
<blockquote><xmp>aws put test681?acl acl.xml
</xmp></blockquote>
Note that the above example changed the ACL for a bucket. The same procedure works to change the ACL for an object.
<p>
</li>
<li>
<b>How do I enable S3 Server Access Logging</b>
<p>
S3 can deliver access logs to some <code>TargetBucket</code>. First, you must grant that <code>TargetBucket</code> <code>WRITE</code> and <code>READ_ACP</code> permission for the log-delivery group.
<blockquote><xmp>$ aws --xml get logging.timkay.com?acl
<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>c1438ce900acb0db547b3708dc29ca60370d8174ee55305050d2990dcf27109c</ID>
<DisplayName>timkay681</DisplayName>
</Owner>
<AccessControlList>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
<ID>c1438ce900acb0db547b3708dc29ca60370d8174ee55305050d2990dcf27109c</ID>
<DisplayName>timkay681</DisplayName>
</Grantee>
<Permission>FULL_CONTROL</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>
$ aws --xml get logging.timkay.com?acl >acl.xml
</xmp></blockquote>
Note that we redirect to <code>acl.xml</code> (with >) rather than as the target file (no >), so that the XML pretty printer gets invoked.
<p>
Next, edit <code>acl.xml</code>, then
<blockquote><xmp>$ cat acl.xml
<AccessControlPolicy xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Owner>
<ID>c1438ce900acb0db547b3708dc29ca60370d8174ee55305050d2990dcf27109c</ID>
<DisplayName>timkay681</DisplayName>
</Owner>
<AccessControlList>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="CanonicalUser">
<ID>c1438ce900acb0db547b3708dc29ca60370d8174ee55305050d2990dcf27109c</ID>
<DisplayName>timkay681</DisplayName>
</Grantee>
<Permission>FULL_CONTROL</Permission>
</Grant>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
<URI>http://acs.amazonaws.com/groups/s3/LogDelivery</URI>
</Grantee>
<Permission>WRITE</Permission>
</Grant>
<Grant>
<Grantee xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="Group">
<URI>http://acs.amazonaws.com/groups/s3/LogDelivery</URI>
</Grantee>
<Permission>READ_ACP</Permission>
</Grant>
</AccessControlList>
</AccessControlPolicy>
$ aws put logging.timkay.com?acl acl.xml
bash-3.00$ aws get logging.timkay.com?acl
+-------------------------------------------------------------------------------------------+--------------+
| Grantee | Permission |
+-------------------------------------------------------------------------------------------+--------------+
| ID=c1438ce900acb0db547b3708dc29ca60370d8174ee55305050d2990dcf27109c DisplayName=timkay681 | FULL_CONTROL |
| URI=http://acs.amazonaws.com/groups/s3/LogDelivery | WRITE |
| URI=http://acs.amazonaws.com/groups/s3/LogDelivery | READ_ACP |
+-------------------------------------------------------------------------------------------+--------------+
</xmp></blockquote>
Next, modify the ?logging attribute for the bucket.
<blockquote><xmp>$ aws --xml get test681?logging
<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<!--<LoggingEnabled>
<TargetBucket>myLogsBucket</TargetBucket>
<TargetPrefix>add/this/prefix/to/my/log/files/access_log-</TargetPrefix>
</LoggingEnabled>
-->
</BucketLoggingStatus>
$ aws --xml get test681?logging >logging.xml
</xmp></blockquote>
edit <code>logging.xml</code>, and then
<blockquote><xmp>$ cat logging.xml
<BucketLoggingStatus xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<LoggingEnabled>
<TargetBucket>logging.timkay.com</TargetBucket>
<TargetPrefix>s3.timkay.com-</TargetPrefix>
</LoggingEnabled>
</BucketLoggingStatus>
$ aws put test681?logging logging.xml
</xmp></blockquote>
<p>
For information on log delivery, see the <a href="http://docs.amazonwebservices.com/AmazonS3/latest/index.html?LogDelivery.html">Amazon documentation</a>.
<p>
</li>
<li>
<b>What if I have more than one AWS account? How do I switch credentials?</b>
<p>
"aws" looks at enviroment variables <code>AWS_ACCESS_KEY_ID</code>, <code>AWS_SECRET_ACCESS_KEY</code>, >code>AWS_SIGN_URL</code>,
<code>EC2_ACCESS_KEY</code>, and <code>EC2_SECRET_KEY</code>
before it decides to read <code>~/.awssecret</code>. If any of those variables is defined, then it will use those credentials and ignore <code>~/.awssecret</code>. For example
<blockquote><code>AWS_ACCESS_KEY_ID=A3CJPJF87DHEJAAG2 AWS_SECRET_ACCESS_KEY=asDc5FD68d7JaIHEuhfLAziplY+ywNTkXq6/8UiO9 aws ls</code></blockquote>
<p>
</li>
<li>
<b>How do I list only some S3 objects from a bucket?</b>
<p>
The TMP bucket has several thousand files in it:
<blockquote><xmp>$ aws ls -1 TMP
aws#1001
aws#1002
...
aws#3003
aws#3004</xmp></blockquote>
To list a selection of them, use BUCKET/PREFIX:
<blockquote><xmp>$ aws ls -1 TMP/aws#176
aws#1760
aws#1761
aws#1762
aws#1763
aws#1764
aws#1765
aws#1766
aws#1767
aws#1768
aws#1769</xmp></blockquote>
Add a prefix to the bucket, and "aws" will return return only those objects that match the prefix. If your bucket has more than 1,000 objects, "aws" automatically issues multiple requests to list them all.
<p>
</li>
<li>
<a name=expires>
<b>How do I generate an S3 request with a long expiration time?</b>
<p>
(As of <code>aws-1.20</code>.)
<blockquote><xmp>$ aws --request --expire-time=1y get s3.timkay.com/tim.jpg
https://s3.timkay.com.s3.amazonaws.com/tim.jpg?AWSAccessKeyId=1B5JPHYQCXW13GWKHAG2&Expires=1255481603&Signature=wxkJ4NqjUgFr2jX25we1SN7ZIF0%3D</xmp></blockquote>
<code>--request</code> prints out the request rather than issuing it, so you can use it multiple times.
<br><code>--expire-time=TIME</code> sets the expiration time. The default is 30 seconds. With no units, indicates seconds. Units can be <code>h</code>, <code>m</code>, <code>d</code>, <code>w</code>, <code>mo</code>, <code>y</code> to indicate hours, minutes, days, weeks, months, or years.
<p>
</li>
<li>
<b>How do I use my domain name to access S3 buckets?</b>
<p>
You can create links that use your domain name (and have an extended expiration time, as above). (As of <code>aws-1.20</code>.)
<p>
<blockquote><xmp>$ aws --dns-alias --http --request --expire-time=1y get s3.timkay.com/tim.jpg
http://s3.timkay.com/tim.jpg?AWSAccessKeyId=1B5JPHYQCXW13GWKHAG2&Expires=1255481684&Signature=6yHAzdF%2F7q68B0lb%2BDh0Cjl6kTQ%3D</xmp></blockquote>
<code>--dns-alias</code> indicates that the bucket name is also a DNS alias (CNAME) pointing to s3.amazonaws.com.
<br><code>--http</code> uses http rather than https. https would cause certificate mismatch errors.
<p>
Of course, if your bucket is marked publicly readable, then you can simply use the path name without authentication information:
<blockquote><code>http://s3.timkay.com/tim.jpg</code></blockquote>
<p>
</li>
<li>
<a name=cache>
<b>How do I store an S3 object with cache control information?</b>
<p>
To send additional headers with any <code>aws put</code> request, simply add the header to the command. The Cache-Control header is supported as of <code>aws-1.21</code>.
<p>
First, without the Cache-Control header:
<blockquote><xmp>$ ./aws-1.21 put "x-amz-acl: public-read" test681 tim.jpg
$ curl --head test681.s3.amazonaws.com/tim.jpg
HTTP/1.1 200 OK
x-amz-id-2: RsyUBxRZ9Aqp3CYGJfBhdhCsUFonLEt3yMZjsZNHsrVcfh5pToadXuCfwBLj406s
x-amz-request-id: 749D1DB1A0CF46B3
Date: Mon, 27 Oct 2008 14:10:38 GMT
Last-Modified: Mon, 27 Oct 2008 14:10:35 GMT
ETag: "c9d5f75d358df75bef47ea11ed3c9f6f"
Content-Type: image/jpg
Content-Length: 37260
Server: AmazonS3
</xmp></blockquote>
Now with the Cache-Control header. Notice that the resulting header contains Cache-Control:
<blockquote><xmp>$ ./aws-1.21 put "x-amz-acl: public-read" "Cache-Control: off" test681 tim.jpg
$ curl --head test681.s3.amazonaws.com/tim.jpg
HTTP/1.1 200 OK
x-amz-id-2: mHZVBuWp8ICRgqN7sUHdFTlzE9tYgwREk08Fwd6yTYz4P1bFFUxPCOBax9n5HXuO
x-amz-request-id: 52D891B26432EFB6
Date: Mon, 27 Oct 2008 14:10:46 GMT
Cache-Control: off
Last-Modified: Mon, 27 Oct 2008 14:10:43 GMT
ETag: "c9d5f75d358df75bef47ea11ed3c9f6f"
Content-Type: image/jpg
Content-Length: 37260
Server: AmazonS3
</xmp></blockquote>
<p>
</li>
<li>
<a name=eu>
<b>How do I use the EU availability zone for EC2?</b>
<p>
Use the <code>--region=eu</code> option (as of <a href=aws-1.22>v1.22</a>).
<blockquote><xmp>$ ./aws-1.22 --region=eu-west-1 dim -o amazon |cut -b -60
+--------------+--------------------------------------------
| imageId | imageLocation
+--------------+--------------------------------------------
| aki-540d2520 | ec2-public-images-eu/vmlinuz-2.6.18-xenU-ec
| aki-550d2521 | ec2-public-images-eu/vmlinuz-2.6.18-xenU-ec
| aki-6a0d251e | ec2-public-images-eu/vmlinuz-2.6.20-1.3002.
| aki-780d250c | ec2-public-images-eu/ec2-vmlinuz-2.6.21.7-2
| aki-7e0d250a | ec2-public-images-eu/ec2-vmlinuz-2.6.21.7-2
| ami-2a0f275e | ec2-public-images-eu/fedora-8-i386-base-v1.
| ami-2e0f275a | ec2-public-images-eu/fedora-8-x86_64-base-v
| ami-520d2526 | ec2-public-images-eu/fedora-8-i386-base-v1.
| ami-5d0d2529 | ec2-public-images-eu/demo-paid-AMI-v1.07.ma
| ami-e40f2790 | ec2-public-images-eu/getting-started.manife
| ari-6b0d251f | ec2-public-images-eu/initrd-2.6.20-1.3002.f
| ari-7d0d2509 | ec2-public-images-eu/ec2-initrd-2.6.21.7-2.
| ari-7f0d250b | ec2-public-images-eu/ec2-initrd-2.6.21.7-2.
+--------------+--------------------------------------------
</xmp></blockquote>
Add <code>--region=eu-west-1</code> to <code>~/.awsrc</code> to make it the default.
<p>
Regsion names <code>eu</code> and <code>us</code> are synonyms for <code>eu-west-1</code> and <code>us-east-1</code>, so <code>--region=eu</code> is a short way to request the European availability zone.
<p>
</li>
<li>
<b>How do I get progress bars for long S3 transfers?</b>
<p>
Use --progress.
<blockquote><xmp>$ aws --progress ls
######################################################################## 100.0%
0 2007-03-04 22:29:34 3.14
0 2007-02-28 18:14:58 3.14159
</xmp></blockquote>
<p>
</li>
<li>
<a name=subd>
<b>How do I create a subdirectory within a S3 bucket?</b>
<p>
S3 doesn't support subdirectories. However, you can use "prefixes" to make something that seems a lot like a subdirectories. Simply add components to the object names that look like subdirectories. Then you can operate on them as though they are subdirectories.
<blockquote><xmp>$ mkdir subd
$ echo hello >subd/hello.txt
$ echo hello, world >subd/world.txt
$ echo not a subdirectory > subd.txt
$ aws put test681 subd/hello.txt
$ aws put test681 subd/world.txt
$ aws put test681 subd.txt
$ aws put test681 /tmp/subd/hello.txt
$ aws ls test681
+---------+--------+--------+---------+-------------+---------------------+--------------------------+----------+--------------+
| Name | Prefix | Marker | MaxKeys | IsTruncated | Key | LastModified | Size | StorageClass |
+---------+--------+--------+---------+-------------+---------------------+--------------------------+----------+--------------+
| test681 | | | 1000 | false | | | | |
| | | | | | /tmp/subd/hello.txt | 2008-12-29T15:24:26.000Z | 6 | STANDARD |
| | | | | | subd/hello.txt | 2008-12-29T15:10:20.000Z | 6 | STANDARD |
| | | | | | subd/world.txt | 2008-12-29T15:10:27.000Z | 13 | STANDARD |
| | | | | | test.txt | 2008-09-14T19:20:51.000Z | 179557 | STANDARD |
| | | | | | tim.jpg | 2008-10-27T14:10:43.000Z | 37260 | STANDARD |
| | | | | | tim2.jpg | 2008-08-15T19:52:10.000Z | 37260 | STANDARD |
| | | | | | tim3.jpg | 2008-08-15T18:20:52.000Z | 37260 | STANDARD |
| | | | | | tim4.jpg | 2008-08-15T18:23:02.000Z | 37260 | STANDARD |
| | | | | | timeyes.gif | 2008-12-27T23:43:52.000Z | 4410 | STANDARD |
+---------+--------+--------+---------+-------------+---------------------+--------------------------+----------+--------------+
</xmp></blockquote>
Note that <code>aws put</code>, when used with no object name, uses the source file name as the object name verbatim. For example, <code>aws put test681 subd/hello.txt</code> and <code>aws put test681 /tmp/subd/hello.txt</code> use <code>subd/hello.txt</code> and <code>/tmp/subd/hello.txt</code> as the object names. (To specify the object name explicitely, try something like <code>aws put test681/hello.txt subd/hello.txt</code>.)
<blockquote><xmp>$ aws ls test681/subd/
+---------+--------+--------+---------+-------------+----------------+--------------------------+------+--------------+
| Name | Prefix | Marker | MaxKeys | IsTruncated | Key | LastModified | Size | StorageClass |
+---------+--------+--------+---------+-------------+----------------+--------------------------+------+--------------+
| test681 | subd/ | | 1000 | false | | | | |
| | | | | | subd/hello.txt | 2008-12-29T15:10:20.000Z | 6 | STANDARD |
| | | | | | subd/world.txt | 2008-12-29T15:10:27.000Z | 13 | STANDARD |
+---------+--------+--------+---------+-------------+----------------+--------------------------+------+--------------+
</xmp></blockquote>
This example shows that the semantics of prefixes does not match the semantics of subdirectories.
<blockquote><xmp>$ aws ls test681/subd
+---------+--------+--------+---------+-------------+----------------+--------------------------+------+--------------+
| Name | Prefix | Marker | MaxKeys | IsTruncated | Key | LastModified | Size | StorageClass |
+---------+--------+--------+---------+-------------+----------------+--------------------------+------+--------------+
| test681 | subd | | 1000 | false | | | | |
| | | | | | subd.txt | 2008-12-29T15:28:18.000Z | 19 | STANDARD |
| | | | | | subd/hello.txt | 2008-12-29T15:10:20.000Z | 6 | STANDARD |
| | | | | | subd/world.txt | 2008-12-29T15:10:27.000Z | 13 | STANDARD |
+---------+--------+--------+---------+-------------+----------------+--------------------------+------+--------------+
</xmp></blockquote>
If you want behavior similar to subdirectories, make sure to include a trailing slash, as in the <code>/subd/</code> example. Some more examples with prefixes follow.
<blockquote><xmp>$ aws ls test681/tim
+---------+--------+--------+---------+-------------+-------------+--------------------------+-------+--------------+
| Name | Prefix | Marker | MaxKeys | IsTruncated | Key | LastModified | Size | StorageClass |
+---------+--------+--------+---------+-------------+-------------+--------------------------+-------+--------------+
| test681 | tim | | 1000 | false | | | | |
| | | | | | tim.jpg | 2008-10-27T14:10:43.000Z | 37260 | STANDARD |
| | | | | | tim2.jpg | 2008-08-15T19:52:10.000Z | 37260 | STANDARD |
| | | | | | tim3.jpg | 2008-08-15T18:20:52.000Z | 37260 | STANDARD |
| | | | | | tim4.jpg | 2008-08-15T18:23:02.000Z | 37260 | STANDARD |
| | | | | | timeyes.gif | 2008-12-27T23:43:52.000Z | 4410 | STANDARD |
+---------+--------+--------+---------+-------------+-------------+--------------------------+-------+--------------+
$ aws ls test681/tmp
+---------+--------+--------+---------+-------------+
| Name | Prefix | Marker | MaxKeys | IsTruncated |
+---------+--------+--------+---------+-------------+
| test681 | tmp | | 1000 | false |
+---------+--------+--------+---------+-------------+
$ aws ls test681//tmp/s
+---------+--------+--------+---------+-------------+---------------------+--------------------------+------+--------------+
| Name | Prefix | Marker | MaxKeys | IsTruncated | Key | LastModified | Size | StorageClass |
+---------+--------+--------+---------+-------------+---------------------+--------------------------+------+--------------+
| test681 | /tmp/s | | 1000 | false | | | | |
| | | | | | /tmp/subd/hello.txt | 2008-12-29T15:24:26.000Z | 6 | STANDARD |
+---------+--------+--------+---------+-------------+---------------------+--------------------------+------+--------------+
</xmp></blockquote>
<p>
</li>
<li>
<b>How do I get return codes, so I can use <code>aws</code> in scripts?</b>
<p>
Normally, when you issue a request to S3, and the request fails (such as "not authorized", or "does not exist"), S3 sets a return code and also returns an error document. "aws" is a wrapper for "curl", and curl handles the actual transaction. In the case that a GET transaction failed, "curl" would return an error document, which would get stored as the requested file. This is not good behavior. The original solution was for "aws" to issue a HEAD request to determine if the GET would succeed. If the HEAD indicated that the GET would proceed, "aws" printed an error message. If so, it would issue the GET, which would write the file. This way, the error document would be avoided.
<p>
Then we discovered that "curl" has a "--fail" option, which tells it to discard any error documents. This is much better behavior. With the --fail option, the HEAD operation is avoided. The GET proceeds, and, in the case of errors, $? is set, because "curl" is run via exec.
<blockquote><xmp>$ ./aws-1.28 --fail get test681/hello.txt ; echo $?
hello, world
0
$ ./aws-1.28 --fail get test681/hello.txtx ; echo $?
curl: (22) The requested URL returned error: 404
22
</xmp></blockquote>
For other things like listing bucket contents, it's more complicated, but it should work. Let me know if I missed any cases.
<p>
</li>
<li>
<a name=elb>
<b>How do I use Elastic Load Balancer (ELB)?</b>
<p>
ELB has been implemented but not tested. If you can help with examples, please send them along.
<p>
<blockquote><xmp>$ ./aws clb testlb --availability-zone us-east-1b --protocol HTTP --loadbalancerport 80 --instanceport 80
+------------------------------------------------------+--------------------------------------+
| CreateLoadBalancerResult | RequestId |
+------------------------------------------------------+--------------------------------------+
| DNSName=testlb-295803881.us-east-1.elb.amazonaws.com | |
| | 4083c40f-b356-11de-8d59-05ca308ff9c0 |
+------------------------------------------------------+--------------------------------------+
$ aws dlb
+-----------------------------------------------------------+--------------------------+------------------+----------------------------------------------+------------------------------------------------------------------------------+-------------------+
| Listeners | CreatedTime | LoadBalancerName | DNSName | HealthCheck | AvailabilityZones |
+-----------------------------------------------------------+--------------------------+------------------+----------------------------------------------+------------------------------------------------------------------------------+-------------------+
| member= Protocol=HTTP LoadBalancerPort=80 InstancePort=80 | 2009-10-07T15:33:41.580Z | testlb | testlb-107942808.us-east-1.elb.amazonaws.com | Interval=30 Target=TCP:80 HealthyThreshold=10 Timeout=5 UnhealthyThreshold=2 | member=us-east-1b |
+-----------------------------------------------------------+--------------------------+------------------+----------------------------------------------+------------------------------------------------------------------------------+-------------------+
+--------------------------------------+
| RequestId |
+--------------------------------------+
| 30f4ce68-b357-11de-991b-a51ca0e65945 |
+--------------------------------------+
$ aws delete-lb testlb
+--------------------------------------+
| RequestId |
+--------------------------------------+
| |
| 7aeca7c8-b357-11de-9187-09f9bb192ed3 |
+--------------------------------------+
</xmp></blockquote>
Additional commands are implemented: enable-zones-for-lb (elbz),
disable-zones-for-lb (dlbz), register-instances-with-lb (rlbi)
deregister-instances-with-lb (dlbi) configure-healthcheck (ch). See
the code for parameter names.
<p>
</li>
<li>
<a name=shareebs>
<b>How do I share Elastic Block Store EBS snapshots?</b>
<blockquote><xmp>$ aws dsa snap-fa3bdc93 --attribute createVolumePermission
+--------------------------------------+---------------+
| requestId | snapshotId |
+--------------------------------------+---------------+
| c2b6e95d-a2c7-4455-a76a-675a747ed502 | snap-fa3bdc93 |
+--------------------------------------+---------------+
$ aws msa snap-fa3bdc93 --attribute createVolumePermission --type add --user 262088988105
+--------------------------------------+--------+
| requestId | return |
+--------------------------------------+--------+
| 941942f0-881e-43af-b62c-1ec091f07e35 | true |
+--------------------------------------+--------+
$ aws dsa snap-fa3bdc93 --attribute createVolumePermission
+--------------------------------------+---------------+---------------------------+
| requestId | snapshotId | createVolumePermission |
+--------------------------------------+---------------+---------------------------+
| 29a4280e-ee2d-4943-ac80-4ee03630755a | snap-fa3bdc93 | item= userId=262088988105 |
+--------------------------------------+---------------+---------------------------+
$ aws rsa snap-fa3bdc93 --attribute createVolumePermission
+--------------------------------------+--------+
| requestId | return |
+--------------------------------------+--------+
| 3ed20378-3aef-43b2-b4a3-de2ee4a3b45d | true |
+--------------------------------------+--------+
$ aws dsa snap-fa3bdc93 --attribute createVolumePermission
+--------------------------------------+---------------+
| requestId | snapshotId |
+--------------------------------------+---------------+
| a4f79542-13c3-487a-b4bf-2b107d4f511d | snap-fa3bdc93 |
+--------------------------------------+---------------+
</xmp></blockquote>
</li>
</ol>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>
<p>