awsam 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,43 @@
1
+ # rcov generated
2
+ coverage
3
+
4
+ # rdoc generated
5
+ rdoc
6
+
7
+ # yard generated
8
+ doc
9
+ .yardoc
10
+
11
+ # bundler
12
+ .bundle
13
+
14
+ # jeweler generated
15
+ pkg
16
+
17
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
+ #
19
+ # * Create a file at ~/.gitignore
20
+ # * Include files you want ignored
21
+ # * Run: git config --global core.excludesfile ~/.gitignore
22
+ #
23
+ # After doing this, these files will be ignored in all your git projects,
24
+ # saving you from having to 'pollute' every project you touch with them
25
+ #
26
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
+ #
28
+ # For MacOS:
29
+ #
30
+ #.DS_Store
31
+ #
32
+ # For TextMate
33
+ #*.tmproj
34
+ #tmtags
35
+ #
36
+ # For emacs:
37
+ #*~
38
+ #\#*
39
+ #.\#*
40
+ #
41
+ # For vim:
42
+ #*.swp
43
+ /Gemfile.lock
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Mike Heffner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,292 @@
1
+ AWSAM (Amazon Web Services Account Manager) allows you to easily manage multiple sets of AWS credentials. It has support for multiple accounts and multiple key-pairs per account.
2
+
3
+ Account switching auto-populates ENV vars used by AWS' command line tools and AWSAM additionally gives you intelligent wrappers for `ssh` and `scp` which can be used like:
4
+
5
+ # ssh by AWS instance id
6
+ $ assh ubuntu@i-123456
7
+
8
+ # ssh by AWS tag name
9
+ $ assh ubuntu@web-node-01
10
+
11
+ # ssh by AWS tag name to an arbitrary node using a substring
12
+ #
13
+ # This example assumes you have the following nodes and that
14
+ # you're indifferent to which node you connect to:
15
+ # web-node-01, web-node-02, web-node-3
16
+ $ assh -f ubuntu@web-node-
17
+
18
+ # scp by instance id
19
+ $ ascp local-file ubuntu@i-123456:remote-file
20
+
21
+ AWSAM supports both AWS' legacy [Java-based CLI tools](http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/SettingUp_CommandLine.html) and their newer [python-based CLI](http://docs.aws.amazon.com/cli/latest/userguide/cli-chap-welcome.html).
22
+
23
+ # Installation
24
+
25
+ 1. Install the gem.
26
+
27
+ $ gem install awsam
28
+
29
+ 2. Install BASH rc file
30
+
31
+ $ raem --init
32
+ Initialized AWS Account Manager
33
+
34
+ Add the following to your .bashrc:
35
+
36
+ if [ -s $HOME/.awsam/bash.rc ]; then
37
+ source $HOME/.awsam/bash.rc
38
+ fi
39
+
40
+ 3. Open a new bash environment.
41
+
42
+ ### Environment variables
43
+
44
+ *AWS Account Manager* sets a variety of environment variables when
45
+ selecting accounts and SSH keypairs. Some of these environment
46
+ variables match the ones used by the Amazon EC2 CLI tools and some our
47
+ unique to AWSAM. It is often convenient to use these environment
48
+ variables in DevOPs scripts in place of hard-coded values -- allowing
49
+ your scripts to be seamlessly used for staging and production
50
+ environments simply by switching the active account with `aem`.
51
+
52
+ The environment variables set when selecting an account are:
53
+
54
+ * `AMAZON_ACCESS_KEY_ID` and `AWS_ACCESS_KEY_ID` and `AWS_ACCESS_KEY` - API access key
55
+
56
+ * `AMAZON_SECRET_ACCESS_KEY` and `AWS_SECRET_ACCESS_KEY` and `AWS_SECRET_KEY` - Secret API access key
57
+
58
+ * `AMAZON_AWS_ID` - The integer ID of this AWS account
59
+
60
+ When selecting an SSH key, the following environment variables are
61
+ set:
62
+
63
+ * `AMAZON_SSH_KEY_NAME` - Name of the keypair.
64
+ * `AMAZON_SSH_KEY_FILE` - Full path to the public key PEM file
65
+
66
+ ### Updating
67
+
68
+ 1. Update repo (fetch && merge) or `gem update awsam`
69
+
70
+ 2. Run `raem --init`. Ignore instructions to setup .bashrc if
71
+ you've already done so.
72
+
73
+ 3. Close and reopen your shell or `source ~/.bashrc`.
74
+
75
+ # General Usage
76
+
77
+ ### Add an account
78
+
79
+ If the environment already contains AWS variables, these will be
80
+ presented as defaults.
81
+
82
+ $ aem add
83
+ Creating a new AWS account...
84
+ Short name: staging
85
+ Description: Staging account
86
+ AWS Region [us-east-1]: us-east-1
87
+ Access key [12346]: 123 *from AWS credentials*
88
+ Secret key [secret123456]: 455 *from AWS credentials*
89
+ AWS ID: aws_account
90
+
91
+ Note: if your shell can't find the `aem` command it is most likely because you haven't successfully sourced `.awsam/bash.rc` in the install steps.
92
+
93
+ ### Select the active account
94
+
95
+ This will update the current environment with the appropriate AWS
96
+ environment variables.
97
+
98
+ $ aem use staging
99
+
100
+ When selecting an account you can mark it as the default account with
101
+ the `--default` option:
102
+
103
+ $ aem use --default staging
104
+
105
+ ### List accounts
106
+
107
+ The active account will be marked with an arrow. The default, if set,
108
+ will be marked with an asterisk.
109
+
110
+ $ aem list
111
+
112
+ AWS Accounts:
113
+
114
+ prod [Librato Production] [1 key: my-prod-key]
115
+ => staging [Staging account]
116
+ *dev [Librato Development] [1 key: devel-key]
117
+
118
+
119
+ ### Import a key pair
120
+
121
+ Add a key to the default account, or the specified account. Defaults
122
+ chosen from current environment if set.
123
+
124
+ $ aem key add my-key-name /path/to/my-keypair.pem
125
+ Imported key pair my-key-name for account staging [Staging account]
126
+
127
+ _The keypair *must* match the name of the keypair in AWS_
128
+
129
+ ### Select a key
130
+
131
+ This will select an SSH keypair to use from your current account and
132
+ set the environment variables `AMAZON_SSH_KEY_NAME` and
133
+ `AMAZON_SSH_KEY_FILE` appropriately. It will also highlight the key in
134
+ the list output with the '>' character.
135
+
136
+ $ aem key use my-key-name
137
+
138
+ $ aem list
139
+
140
+ AWS Accounts:
141
+
142
+ staging [Staging account]
143
+ => dev [Librato Development] [1 key: >my-key-name]
144
+
145
+ You can also define a default key for each account that will
146
+ automatically be selected when the account is chosen. Just use the
147
+ `--default` option when selecting a key to set a default key. Picking
148
+ a default will place an asterisk next to the key name in the `aem
149
+ list` output.
150
+
151
+ $ aem key use --default my-key-name
152
+
153
+ ### assh utility: SSH by instance ID
154
+
155
+ Instance IDs will be looked up using the current account details. If
156
+ the instance's keypair name exists, that keyfile will be used as the
157
+ identity file to ssh.
158
+
159
+ Usage:
160
+
161
+ $ assh [user@]<instance-id>
162
+
163
+ Example:
164
+
165
+ $ assh ubuntu@i-123456
166
+ warning: peer certificate won't be verified in this SSL session
167
+ Loging in as ubuntu to ec2-1.2.3.4.compute-1.amazonaws.com
168
+
169
+ ...
170
+
171
+ ubuntu@host:~$
172
+
173
+ ### assh utility: SSH by tag name
174
+
175
+ Instances will be looked up by their tag name. This tag name can be found assigned to the "value" key when you run ec2-describe-tags, using the AWS CLI Tools.
176
+
177
+ Usage:
178
+
179
+ $ assh [user@]<instance tag name>
180
+
181
+ Example:
182
+
183
+ $ assh ubuntu@web-node-01
184
+ warning: peer certificate won't be verified in this SSL session
185
+ Loging in as ubuntu to ec2-1.2.3.4.compute-1.amazonaws.com
186
+
187
+ ...
188
+
189
+ ubuntu@web-node-01:~$
190
+
191
+ If you use assh with a substringed tag name which matches against several nodes, you will have the option to choose a specific node. For example, let's say you have 3 nginx nodes all running the same code and your nodes are named:
192
+
193
+ web-node-01, web-node-02, web-node-03
194
+
195
+ Then you run the following from within your terminal:
196
+
197
+ Usage:
198
+
199
+ $ assh ubuntu@web-node-
200
+ Please select which node you wish to use:
201
+ 0) web-node-01 (i-43dfed45)
202
+ 1) web-node-02 (i-789eft24)
203
+ 2) web-node-03 (i-546fer56)
204
+ > 1
205
+
206
+ You'll notice that you're given a list of the nodes in your account that match the "web-node-*" pattern. The instance ID associated with each node is appended to each option as well. You will then be given a prompt (>) where you enter the index of the node you want to connect to.
207
+
208
+ Finally, if you use assh with a substringed tag name using the -f option, you can pass the base substring of a cluster of common nodes to connect to an **arbitrary** node within that cluster. The -f option assumes you have 'n' number of machines using a shared base name, all running mirrored environments. Once again, we will use the web-node-[01,02,03] scenario from our previous example:
209
+
210
+ Usage:
211
+
212
+ $ assh -f [user@]web-node-
213
+
214
+ In this example, you would automatically connect to one of the machines in your account which matches the "web-node-*" pattern without having to explicitly choose a node.
215
+
216
+ #### assh utility: questions/help?
217
+ Run the following from your terminal:
218
+
219
+ $ assh --help
220
+
221
+ or:
222
+
223
+ $ assh -h
224
+
225
+ ### ascp utility: SCP by instance ID
226
+
227
+ Instance IDs will be looked up using the current account details. If
228
+ the instance's keypair name exists, that keyfile will be used as the
229
+ identity file to scp.
230
+
231
+ Usage:
232
+
233
+ $ ascp [user@]<instance ID>:remote-file local-file
234
+ $ ascp local-file [user@]<instance ID>:remote-file
235
+
236
+ ### Default user
237
+
238
+ You can specify a default user to *assh* by setting
239
+ `AWS_DEFAULT_USER`:
240
+
241
+ ```
242
+ $ AWS_DEFAULT_USER=ubuntu assh datanode
243
+ Please select which node you wish to use:
244
+
245
+ 0) metrics_facing-stg-v2-datanode-11 (i-30XXXXX, m1.large, 2014-02-12T20:46:29.000Z)
246
+ 1) metrics_facing-stg-v2-datanode-12 (i-91XXXXX, m1.large, 2014-02-13T04:20:32.000Z)
247
+ 2) metrics_facing-stg-v2-datanode-13 (i-64XXXXX, m1.large, 2014-03-04T18:59:26.000Z)
248
+ q) Quit
249
+
250
+ > 2
251
+
252
+ Logging in as ubuntu to ec2-XXXX.compute-1.amazonaws.com
253
+ ```
254
+
255
+ ### Remove a key
256
+
257
+ You can remove ah SSH key from an account (defaults to the current
258
+ account).
259
+
260
+ $ aem key remove --acct prod my-prod-key
261
+
262
+ ### Remove an account
263
+
264
+ You can remove an account as long as it is not the active one.
265
+
266
+ $ aem remove staging
267
+
268
+ ## Contributing to awsam
269
+
270
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
271
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
272
+ * Fork the project
273
+ * Start a feature/bugfix branch
274
+ * Commit and push until you are happy with your contribution
275
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
276
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
277
+
278
+ ### TODO List
279
+
280
+ assh utility:
281
+
282
+ * ssh to a tag name (multiple?)
283
+ * caches instance id => hostname for fast lookup
284
+ * determines user?
285
+ * supports complete SSH CLI options
286
+ * inline commands, eg: `ssh user@instance sudo tail /var/log/messages`
287
+
288
+ ## Copyright
289
+
290
+ Copyright (c) 2011 Mike Heffner. See LICENSE.txt for
291
+ further details.
292
+
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'awsam/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "awsam"
8
+ spec.version = Awsam::VERSION
9
+ spec.authors = ["Mike Heffner"]
10
+ spec.email = ["mikeh@fesnel.com"]
11
+ spec.summary = %q{Amazon Web Services Account Manager}
12
+ spec.description = %q{Amazon Web Services Account Manager (modeled after 'rvm')}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency 'right_aws', '3.1.0'
22
+ spec.add_dependency 'trollop', '2.0'
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,370 @@
1
+ function __aem_active()
2
+ {
3
+ echo "$AWSAM_ACTIVE_ACCOUNT"
4
+ }
5
+
6
+ function __aem_active_key()
7
+ {
8
+ echo "$AWSAM_ACTIVE_KEY"
9
+ }
10
+
11
+ function __aem_usage()
12
+ {
13
+ echo "Usage: aem <command> [<args>]"
14
+ echo
15
+ echo "Possible commands:"
16
+ echo
17
+ echo " add Add a new AWS account"
18
+ echo
19
+ echo " remove NAME Remove the NAME account"
20
+ echo
21
+ echo " key <cmd>"
22
+ echo " +-> add [--acct <ACCT>] KEYNAME KEYFILE"
23
+ echo " | Add key to ACCT or default to active one"
24
+ echo " +-> remove [--acct <ACCT>] KEYNAME"
25
+ echo " | Remove key from ACCT or default"
26
+ echo " +-> use [--default] KEYNAME"
27
+ echo " Use the KEYNAME from the current account"
28
+ echo " Will set the key as the default for the"
29
+ echo " account if the --default option is set"
30
+ echo
31
+ echo " list List AWS accounts"
32
+ echo
33
+ echo " use [--default] NAME"
34
+ echo " Use the NAME account. Set as default if"
35
+ echo " the option --default is specified"
36
+ echo
37
+ }
38
+
39
+ # Fail with error message and print usage
40
+ function __aem_fusage()
41
+ {
42
+ local MSG="$*"
43
+
44
+ if [ -n "$MSG" ]; then
45
+ printf "ERROR: $MSG\n" >&2
46
+ # Add a blank between error and usage
47
+ echo
48
+ fi
49
+
50
+ __aem_usage
51
+ }
52
+
53
+ # Just print message to standard output
54
+ function __aem_fail()
55
+ {
56
+ local MSG="$*"
57
+
58
+ if [ -n "$MSG" ]; then
59
+ printf "ERROR: $MSG\n" >&2
60
+ fi
61
+ }
62
+
63
+ function __aem_add()
64
+ {
65
+
66
+ raem --add
67
+ }
68
+
69
+ function __aem_remove()
70
+ {
71
+ if [ $# -ne 1 ]; then
72
+ __aem_fusage "Remove requires an argument"
73
+ return 1
74
+ fi
75
+
76
+ local ACCT="$1"
77
+ if [ "$ACCT" = "$(__aem_active)" ]; then
78
+ __aem_fail "Can not remove the active account"
79
+ return 1
80
+ fi
81
+
82
+ raem --remove --account "$ACCT"
83
+ }
84
+
85
+ function __aem_key_add()
86
+ {
87
+ local KEYNAME=""
88
+ local KEYFILE=""
89
+ local ACCT=""
90
+
91
+ while [ $# -gt 0 ]; do
92
+ if [ "$1" = "--acct" ]; then
93
+ shift
94
+ if [ $# -lt 1 ]; then
95
+ __aem_fusage "--acct requires argument"
96
+ return 1
97
+ fi
98
+
99
+ ACCT="$1"
100
+ shift
101
+ continue
102
+ fi
103
+
104
+ if [ -z "$KEYNAME" ]; then
105
+ KEYNAME="$1"
106
+ else
107
+ KEYFILE="$1"
108
+ fi
109
+ shift
110
+ done
111
+
112
+ if [ -z "$KEYNAME" -o -z "$KEYFILE" ]; then
113
+ __aem_fusage "Insufficient arguments"
114
+ return 1
115
+ fi
116
+
117
+ if [ -z "$ACCT" ]; then
118
+ ACCT=$(__aem_active)
119
+ if [ -z "$ACCT" ]; then
120
+ __aem_fail "No account specified and none active."
121
+ return 1
122
+ fi
123
+ fi
124
+
125
+ raem --import-key --account "$ACCT" --keyname "$KEYNAME" \
126
+ --keyfile "$KEYFILE"
127
+ }
128
+
129
+ function __aem_key_remove()
130
+ {
131
+ local KEYNAME=""
132
+ local ACCT=""
133
+
134
+ while [ $# -gt 0 ]; do
135
+ if [ "$1" = "--acct" ]; then
136
+ shift
137
+ if [ $# -lt 1 ]; then
138
+ __aem_fusage "--acct requires argument"
139
+ return 1
140
+ fi
141
+
142
+ ACCT="$1"
143
+ shift
144
+ continue
145
+ fi
146
+
147
+ KEYNAME="$1"
148
+ shift
149
+ done
150
+
151
+ if [ -z "$KEYNAME" ]; then
152
+ __aem_fusage "Must specify key to remove"
153
+ return 1
154
+ fi
155
+
156
+ if [ -z "$ACCT" ]; then
157
+ ACCT=$(__aem_active)
158
+ if [ -z "$ACCT" ]; then
159
+ __aem_fail "No account specified and none active."
160
+ return 1
161
+ fi
162
+ fi
163
+
164
+ # Unset active key
165
+ if [ "$KEYNAME" = "$(__aem_active_key)" ]; then
166
+ unset AWSAM_ACTIVE_KEY
167
+ fi
168
+
169
+ raem --remove-key --account "$ACCT" --keyname "$KEYNAME"
170
+ }
171
+
172
+ function __aem_key_use()
173
+ {
174
+ if [ $# -lt 1 ]; then
175
+ __aem_fusage "Must specify keyname"
176
+ return 1
177
+ fi
178
+
179
+ local ACCT
180
+ local SETDEFAULT=0
181
+ local KEYNAME=""
182
+
183
+ while [ $# -gt 0 ]; do
184
+ if [ "$1" == "--default" ]; then
185
+ SETDEFAULT=1
186
+ shift
187
+ continue
188
+ fi
189
+
190
+ if [ -n "$KEYNAME" ]; then
191
+ __aem_fusage "Invalid argument to key use command"
192
+ return 1
193
+ fi
194
+
195
+ KEYNAME="$1"
196
+ shift
197
+ done
198
+
199
+ if [ -z "$KEYNAME" ]; then
200
+ __aem_fusage "Must specify key name"
201
+ return 1
202
+ fi
203
+
204
+ ACCT=$(__aem_active)
205
+ if [ -z "$ACCT" ]; then
206
+ __aem_fail "Must select an account first"
207
+ return 1
208
+ fi
209
+
210
+ local ENV
211
+ if [ $SETDEFAULT -ne 0 ]; then
212
+ # Will set the key as the default
213
+ ENV=$(raem --environ-key --account $ACCT --default --keyname $KEYNAME)
214
+ else
215
+ ENV=$(raem --environ-key --account $ACCT --keyname $KEYNAME)
216
+ fi
217
+ if [ $? -ne 0 ]; then
218
+ __aem_fail "Failed to select key $KEYNAME"
219
+ return 1
220
+ fi
221
+
222
+ eval $ENV
223
+ export AWSAM_ACTIVE_KEY=$KEYNAME
224
+ }
225
+
226
+ function __aem_key()
227
+ {
228
+ if [ $# -lt 1 ]; then
229
+ __aem_fusage "Key cmd requires an argument"
230
+ return 1
231
+ fi
232
+
233
+ local key_cmd="$1"
234
+ shift
235
+
236
+ case "$key_cmd" in
237
+ add)
238
+ __aem_key_add "$@"
239
+ return $?
240
+ ;;
241
+ remove)
242
+ __aem_key_remove "$@"
243
+ return $?
244
+ ;;
245
+ use)
246
+ __aem_key_use "$@"
247
+ return $?
248
+ ;;
249
+ *)
250
+ echo "Unknown key command: $key_cmd"
251
+ return 1;
252
+ ;;
253
+ esac
254
+ }
255
+
256
+ function __aem_list()
257
+ {
258
+ raem --list
259
+ }
260
+
261
+ function __aem_use()
262
+ {
263
+ local ACCT
264
+ local ENV
265
+ local SETDEFAULT=0
266
+
267
+ while [ $# -gt 0 ]; do
268
+ if [[ "$1" == "--default" ]]; then
269
+ SETDEFAULT=1
270
+ shift
271
+ continue
272
+ fi
273
+
274
+ if [ -n "$ACCT" ]; then
275
+ __aem_fusage "Invalid arguments to use command"
276
+ return 1
277
+ fi
278
+
279
+ ACCT="$1"
280
+ shift
281
+ done
282
+
283
+ if [ -z "$ACCT" ]; then
284
+ __aem_fusage "use command requires account name"
285
+ return 1
286
+ fi
287
+
288
+ if [ $SETDEFAULT -eq 0 ]; then
289
+ ENV=$(raem --environ --account $ACCT)
290
+ else
291
+ ENV=$(raem --environ --default --account $ACCT)
292
+ fi
293
+ if [ $? -ne 0 ]; then
294
+ __aem_fail "No such account: $ACCT"
295
+ return 1
296
+ fi
297
+
298
+ eval $ENV
299
+ export AWSAM_ACTIVE_ACCOUNT=$ACCT
300
+
301
+ # Clear active key
302
+ unset AWSAM_ACTIVE_KEY
303
+
304
+ # Check if there is a default key
305
+ DEFAULT=$(raem --account $ACCT --print-default-key)
306
+ if [ $? -eq 0 ]; then
307
+ aem key use "$DEFAULT"
308
+ fi
309
+
310
+ # Create IAM credential file that is required by AWS IAM CLI tools
311
+ CREDENTIALS_FILE="${HOME}/.awsam/credentials.txt"
312
+
313
+ touch ${CREDENTIALS_FILE}
314
+ chmod 0600 ${CREDENTIALS_FILE}
315
+
316
+ echo "AWSAccessKeyId=${AWS_ACCESS_KEY_ID}" > ${CREDENTIALS_FILE}
317
+ echo "AWSSecretKey=${AWS_SECRET_ACCESS_KEY}" >> ${CREDENTIALS_FILE}
318
+
319
+ return 0
320
+ }
321
+
322
+ function aem()
323
+ {
324
+
325
+ if [ $# -lt 1 ]; then
326
+ __aem_usage
327
+ return 0
328
+ fi
329
+
330
+ if ! `which raem > /dev/null 2>&1`; then
331
+ __aem_fail "Unable to find 'raem' binary in PATH";
332
+ return 1
333
+ fi
334
+
335
+ local aem_cmd="$1"
336
+ shift
337
+
338
+ case "$aem_cmd" in
339
+ add)
340
+ __aem_add
341
+ ;;
342
+ remove)
343
+ __aem_remove "$@"
344
+ ;;
345
+ key)
346
+ __aem_key "$@"
347
+ ;;
348
+ list)
349
+ __aem_list
350
+ ;;
351
+ use)
352
+ __aem_use "$@"
353
+ ;;
354
+ *)
355
+ __aem_fusage "Unknown command: $aem_cmd"
356
+ return 1
357
+ esac
358
+
359
+ return $?
360
+ }
361
+
362
+ # Check for default account
363
+ DEFAULT=$(raem --print-default-acct)
364
+ if [ $? -eq 0 ]; then
365
+ __aem_use "$DEFAULT"
366
+ fi
367
+
368
+ # Local Variables:
369
+ # mode: shell-script
370
+ # End: