-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathaws.re
171 lines (119 loc) · 5.15 KB
/
aws.re
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
#@#
=={aws} @<term>{aws}
awsコマンドを使うと、
コマンドラインからAWSサービスを利用できる。
AWS固有のコマンドなので、当然Unix標準ではない。
AWS提供のEC2のOSイメージではawsコマンドが標準搭載のようだが、
OSによっては別途インストールが必要である
=== 書式
//list[][][fontsize=xx-small]{
$ aws [options] command subcommand [parameters]
//}
* command部分とsubcommand部分の指定は必須である
** command部分にはサービス名(例:ec2、s3)を指定する
** subcommand部分では、そのcommandサービス固有の動作指定を行う
* [options]と[parameters]はオプション
=== 実行例
==== 実行例 (引数がなくエラー、ヘルプメッセージが表示される)
//list[][][fontsize=xx-small]{
$ aws
//}
==== 実行結果
//list[][][fontsize=xx-small]{
$ aws
To see help text, you can run:
aws help
aws <command> help
aws <command> <subcommand> help
aws: error: the following arguments are required: command
//}
aws単体だとエラーとヘルプメッセージが表示される。
//note[show-help-by-error][コマンドの使い方が分からない時]{
@<idx>{コマンド((こまんど))<<>>の使い方が分からない時((のつかいかたがわからないとき))}に、
「わざとエラーを起こしてヘルプメッセージを表示させる」技は、
ほぼ、どんなときでも使えるので覚えておきたい
//}
=== @<idx>{aws<<>> s3} subcommand
awsで使えるコマンドは様々であるが、今回はサービスの一つであるS3のみを紹介する。
@<B>{S3(Simple Storage Service)}はAWSを代表するサービスの一つである。
きわめて耐久性が高く、
@<B>{99.999999999%(イレブン・ナイン)を超えるデータ耐久性}を唱う。
S3の代表的な使い方は
「@<idx>{ストレージ((すとれーじ))}サービス(データの長期保存)」と
「@<idx>{静的Webサイト((せいてきうえぶさいと))}(事前にHTMLを作成し、その通りに動くサイト)の公開」である。
S3を利用する際には、まず@<B>{バケット}と呼ばれるファイルの入れ物を作成する。
これはUnixのディレクトリやWindowsのフォルダに相当するものと考えて良い。
ユーザは、このバケットにファイルをアップロードしていくことになる。
awsコマンドでS3サービスを呼び出す場合、command部分にはs3を指定する。
subcommandで様々なファイル操作が行える。例:
* バケットの内部を確認する際は ls
* データの送受信は cp もしくは sync
** cpはファイル、syncはバケットとフォルダを同期
@<br>{}
注:操作方法はcpもsyncも同じなのでsyncの実行例は省略する
==== 前提
以下の実行例では、次の前提がある
* @<code>{$ }行は、AWSのEC2にログインしている状態での操作である
** ユーザadminのホームディレクトリ(/home/admin)で作業している
** このディレクトリにはwww.pyファイルとhtdocsディレクトリがある
* AWS S3の管理画面で、事前にバケットは作成済
** バケット名はtestBucket
* バケットはURLで指定する。
書式は@<code>{プロトコル://バケット名}
** @<code>{s3://testBucket}
=== 実行例: S3バケットの中身を確認する (@<idx>{aws<<>> s3 ls})
@<code>{aws s3 ls}でバケットの中身を確認できる。
lsコマンドの素直な拡張といえる
(@<secref>{ls}節も参照)
==== 書式
//list[][][fontsize=xx-small]{
$ aws s3 ls バケットのURL
//}
==== 実行例
//list[][][fontsize=xx-small]{
$ aws s3 ls s3://testBucket
//}
==== 実行結果
//list[][][fontsize=xx-small]{
$ aws s3 ls s3://testBucket
hello.py
//}
バケットにファイルhello.pyがあると表示されている
=== 実行例: ファイルをS3に送る (@<idx>{aws<<>> s3 cp})
EC2上のwww.pyをS3バケットにコピーする
==== 書式
//list[][][fontsize=xx-small]{
$ aws s3 cp ファイル名 バケットのURL
//}
==== 実行例
//list[][][fontsize=xx-small]{
$ aws s3 cp ファイル名 s3://testBucket
//}
==== 実行結果
//list[][][fontsize=xx-small]{
$ aws s3 cp www.py s3://testBucket
//}
無事にコピーされたかどうか?は、@<code>{aws s3 ls}コマンドを再度実行してみるか、AWS S3の管理画面で確認する
//list[][][fontsize=xx-small]{
$ aws s3 ls s3://testBucket
hello.py www.py
//}
=== 実行例: S3からファイルを取り出す (aws s3 cp)
==== 書式
//list[][][fontsize=xx-small]{
$ aws s3 cp s3://testBucket/ファイル名 .
$ aws s3 cp s3://testBucket/ファイル名 ファイル名
$ aws s3 cp s3://testBucket/ファイル名 ディレクトリ名
//}
==== 実行例
//list[][][fontsize=xx-small]{
$ aws s3 cp s3://testBucket/hello.py hello.py
//}
S3バケットにあるhello.pyをEC2内にhello.pyという名前でコピーする
==== 実行結果
//list[][][fontsize=xx-small]{
$ aws s3 cp s3://testBucket/hello.py hello.py
$ ls
hello.py www.py htdocs
//}
EC2上にhello.pyファイルが増えたことが分かる