sonic-screwdriver 1.4.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/bin/commit_docs.sh +26 -0
- data/.circleci/config.yml +70 -0
- data/.gitignore +1 -1
- data/.ruby-version +1 -0
- data/CHANGELOG.md +13 -2
- data/Gemfile +3 -3
- data/Gemfile.lock +43 -14
- data/Guardfile +17 -10
- data/LICENSE.txt +2 -2
- data/README.md +10 -10
- data/Rakefile +9 -2
- data/docs/_config.yml +3 -0
- data/docs/_docs/help.md +1 -1
- data/docs/_docs/install-bastion.md +5 -15
- data/docs/_docs/install.md +3 -3
- data/docs/_docs/settings.md +40 -56
- data/docs/_docs/tutorial-ecs-exec.md +16 -20
- data/docs/_docs/tutorial-ecs-sh.md +73 -0
- data/docs/_docs/tutorial-execute.md +93 -17
- data/docs/_docs/tutorial-ssh.md +13 -18
- data/docs/_docs/why-ec2-run-command.md +1 -1
- data/docs/_includes/commands.html +5 -5
- data/docs/_includes/content.html +5 -0
- data/docs/_includes/css/main.css +15 -9
- data/docs/_includes/css/sonic.css +7 -5
- data/docs/_includes/example.html +4 -4
- data/docs/_includes/reference.md +1 -0
- data/docs/_includes/subnav.html +2 -1
- data/docs/_reference/sonic-completion.md +44 -0
- data/docs/_reference/sonic-completion_script.md +25 -0
- data/docs/_reference/sonic-ecs-exec.md +30 -0
- data/docs/_reference/sonic-ecs-help.md +21 -0
- data/docs/_reference/sonic-ecs-sh.md +35 -0
- data/docs/_reference/sonic-ecs.md +25 -0
- data/docs/_reference/sonic-execute.md +84 -0
- data/docs/_reference/sonic-list.md +40 -0
- data/docs/_reference/sonic-ssh.md +86 -0
- data/docs/_reference/sonic-version.md +21 -0
- data/docs/img/tutorials/ec2-console-run-command.png +0 -0
- data/docs/quick-start.md +9 -10
- data/docs/reference.md +12 -0
- data/{bin → exe}/sonic +3 -3
- data/lib/bash_scripts/docker-exec.sh +1 -0
- data/lib/bash_scripts/docker-run.sh +8 -1
- data/lib/sonic.rb +10 -2
- data/lib/sonic/{aws_services.rb → aws_service.rb} +6 -1
- data/lib/sonic/base_command.rb +82 -0
- data/lib/sonic/cli.rb +37 -27
- data/lib/sonic/command.rb +8 -22
- data/lib/sonic/completer.rb +161 -0
- data/lib/sonic/completer/script.rb +6 -0
- data/lib/sonic/completer/script.sh +10 -0
- data/lib/sonic/core.rb +15 -0
- data/lib/sonic/default/settings.yml +6 -16
- data/lib/sonic/docker.rb +29 -1
- data/lib/sonic/ecs.rb +22 -0
- data/lib/sonic/execute.rb +153 -18
- data/lib/sonic/help.rb +9 -0
- data/lib/sonic/help/command/send.md +10 -0
- data/lib/sonic/help/completion.md +22 -0
- data/lib/sonic/help/completion_script.md +3 -0
- data/lib/sonic/help/ecs/exec.md +8 -0
- data/lib/sonic/help/ecs/sh.md +13 -0
- data/lib/sonic/help/execute.md +60 -0
- data/lib/sonic/help/list.md +17 -0
- data/lib/sonic/help/ssh.md +60 -0
- data/lib/sonic/list.rb +4 -1
- data/lib/sonic/setting.rb +47 -0
- data/lib/sonic/ssh.rb +41 -20
- data/lib/sonic/ssh/identifier_detector.rb +6 -2
- data/lib/sonic/version.rb +1 -1
- data/sonic.gemspec +14 -9
- data/spec/lib/cli_spec.rb +5 -10
- data/spec/lib/sonic/execute_spec.rb +0 -1
- data/spec/spec_helper.rb +18 -10
- metadata +115 -16
- data/docs/_docs/tutorial-ecs-run.md +0 -100
- data/lib/sonic/cli/help.rb +0 -152
- data/lib/sonic/settings.rb +0 -115
data/docs/_docs/install.md
CHANGED
@@ -30,14 +30,14 @@ For more information about the Bolts Toolbelt or to get an installer for another
|
|
30
30
|
|
31
31
|
For a small set of the commands there are server side dependencies.
|
32
32
|
|
33
|
-
#### sonic ecs
|
33
|
+
#### sonic ecs dependencies
|
34
34
|
|
35
|
-
For the `sonic ecs
|
35
|
+
For the `sonic ecs` commands to work `jq` is required on the server side. This is covered in the [How It Works]({% link _docs/how-it-works.md %}) section.
|
36
36
|
|
37
37
|
One way to install `jq` quickly is by using the `sonic execute` command. For example:
|
38
38
|
|
39
39
|
```sh
|
40
|
-
sonic execute hi-web
|
40
|
+
sonic execute hi-web yum install -y jq
|
41
41
|
```
|
42
42
|
|
43
43
|
It is recommended that you install `jq` with the UserData script or bake it into the AMI though.
|
data/docs/_docs/settings.md
CHANGED
@@ -2,92 +2,76 @@
|
|
2
2
|
title: Settings
|
3
3
|
---
|
4
4
|
|
5
|
-
You can adjust the behavior of sonic and set some handy default values with
|
5
|
+
You can adjust the behavior of sonic and set some handy default values with settings files. The settings files used are determined by the value of environment variable `SONIC_PROFILE` or `AWS_PROFILE`. The value determines the settings profile to use. There can exist multiple settings files which all get loaded and merged. The options from the files follow the following precedence rules:
|
6
6
|
|
7
|
-
1. current folder - The current folder's `.sonic/
|
8
|
-
2. user - The user's `~/.sonic/
|
7
|
+
1. current folder - The current folder's `.sonic/[AWS_PROFILE].yml` values take the highest precedence. The current folder is typically the project folder.
|
8
|
+
2. user - The user's `~/.sonic/[AWS_PROFILE].yml` values take the second highest precedence.
|
9
9
|
3. default - The [default settings](https://github.com/boltopslabs/sonic/blob/master/lib/sonic/default/settings.yml) bundled with the tool takes the lowest precedence.
|
10
10
|
|
11
|
-
|
11
|
+
A concrete example helps explain it. Let's say `AWS_PROFILE=prod-profile` with the following files:
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
default: # default is nil - which means a bastion host wont be used
|
16
|
-
# Examples:
|
17
|
-
# prod: bastion.mydomain.com
|
18
|
-
# stag: ubuntu@bastion-stag.mydomain.com
|
19
|
-
host_key_check: false
|
20
|
-
service_cluster:
|
21
|
-
default: # defaults to nil
|
22
|
-
hi-web-prod: prod
|
23
|
-
hi-clock-prod: prod
|
24
|
-
hi-worker-prod: prod
|
25
|
-
hi-web-stag: stag
|
26
|
-
hi-clock-stag: stag
|
27
|
-
hi-worker-stag: stag
|
28
|
-
user: ec2-user
|
29
|
-
```
|
13
|
+
* in current folder: `.sonic/prod-profile.yml`
|
14
|
+
* in user home folder: `~/.sonic/prod-profile.yml`
|
30
15
|
|
31
|
-
|
32
|
-
|
33
|
-
Setting | Description | Default
|
34
|
-
------------- | ------------- | -------------
|
35
|
-
bastion | Bastion mapping allows you to set a bastion host on a per ECS cluster basis. The bastion host is used as the jump host. Examples: bastion.mydomain.com, myuser@bastion.myuser.com or 123.123.123.123. | (no value)
|
36
|
-
host_key_check | Controls whether or not use the strict host checking ssh option. Since EC2 server host changes often the default value is false. | false
|
37
|
-
service_cluster | Service to cluster mapping. This is a Hash structure that maps the service name to cluster names. | (no value)
|
38
|
-
user | User to ssh into the server with. This can be overriden at the CLI with the user@host notation but can be set in the settings.yml file also. | ec2-user
|
16
|
+
Then the `.sonic/prod-profile.yml` gets merged into `~/.sonic/prod-profile.yml` and that in turn gets merged into sonic's [default settings](https://github.com/boltopslabs/sonic/blob/master/lib/sonic/default/settings.yml).
|
39
17
|
|
40
|
-
|
18
|
+
You can also use the `SONIC_PROFILE=prod-profile` environment variable instead of the `AWS_PROFILE` environment variable. The `SONIC_PROFILE` wins over the `AWS_PROFILE` value.
|
41
19
|
|
42
|
-
|
20
|
+
## Full Example
|
43
21
|
|
44
|
-
|
22
|
+
Here is an `prod-profile.yml` example:
|
45
23
|
|
46
24
|
```yaml
|
47
25
|
bastion: # cluster_host mapping
|
48
|
-
|
49
|
-
|
50
|
-
|
26
|
+
user: ec2-user
|
27
|
+
host: # default is nil - which means a bastion host wont be used
|
28
|
+
host_key_check: false
|
29
|
+
|
30
|
+
# used with `sonic ecs ssh` command
|
31
|
+
ecs_service_cluster_map:
|
32
|
+
default: default # default cluster
|
33
|
+
hi-web: production
|
34
|
+
hi-clock: production
|
35
|
+
hi-worker: production
|
51
36
|
```
|
52
37
|
|
53
|
-
|
38
|
+
The following table covers the different setting options:
|
54
39
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
40
|
+
Setting | Description | Default
|
41
|
+
------------- | ------------- | -------------
|
42
|
+
bastion.user | User to ssh into the server with. This can be overriden at the CLI with the user@host notation but can be set in the settings.yml file also. | ec2-user
|
43
|
+
bastion.host | Bastion mapping allows you to set a bastion host on a per ECS cluster basis. The bastion host is used as the jump host. Examples: bastion.mydomain.com, myuser@bastion.myuser.com or 123.123.123.123. | (no value)
|
44
|
+
bastion.host_key_check | Controls whether or not use the strict host checking ssh option. Since EC2 server host changes often the default value is false. | false
|
45
|
+
ecs_service_cluster_map | Service to cluster mapping. This is a Hash structure that maps the service name to cluster names. | (no value)
|
46
|
+
|
47
|
+
The default settings are located tool source code at [lib/sonic/default/settings.yml](https://github.com/boltopslabs/sonic/blob/master/lib/sonic/default/settings.yml).
|
60
48
|
|
61
49
|
### Service to Cluster Mapping
|
62
50
|
|
63
|
-
|
51
|
+
A useful option is the `ecs_service_cluster_map`. This option maps ecs service names to cluster names. This saves you from typing the `--cluster` option repeatedly. Here is an example `~/.sonic/settings.yml`:
|
64
52
|
|
65
53
|
```yaml
|
66
|
-
|
67
|
-
service_cluster:
|
54
|
+
ecs_service_cluster_map:
|
68
55
|
default: my-default-cluster
|
69
|
-
hi-web
|
70
|
-
hi-clock
|
71
|
-
hi-worker
|
72
|
-
hi-web-stag: stag
|
73
|
-
hi-clock-stag: stag
|
74
|
-
hi-worker-stag: stag
|
56
|
+
hi-web: production
|
57
|
+
hi-clock: production
|
58
|
+
hi-worker: production
|
75
59
|
```
|
76
60
|
|
77
61
|
This results in shorter commands:
|
78
62
|
|
79
63
|
```
|
80
|
-
sonic ssh hi-web
|
81
|
-
sonic ssh hi-clock
|
82
|
-
sonic ssh hi-worker
|
64
|
+
sonic ecs ssh hi-web
|
65
|
+
sonic ecs ssh hi-clock
|
66
|
+
sonic ecs ssh hi-worker
|
83
67
|
```
|
84
68
|
|
85
69
|
Instead of what you normally would have to type:
|
86
70
|
|
87
71
|
```
|
88
|
-
sonic ssh hi-web
|
89
|
-
sonic ssh hi-clock
|
90
|
-
sonic ssh hi-worker
|
72
|
+
sonic ecs ssh hi-web --cluster production
|
73
|
+
sonic ecs ssh hi-clock --cluster production
|
74
|
+
sonic ecs ssh hi-worker --cluster production
|
91
75
|
```
|
92
76
|
|
93
77
|
|
@@ -8,26 +8,24 @@ One of the additional things `sonic` can do is hop one more level and get you al
|
|
8
8
|
|
9
9
|
It does this with a variety of scripts and trickery and is covered in [How It Works]({% link _docs/how-it-works.md %}). Let's go through examples of how sonic can help you get into an running ECS docker container quickly.
|
10
10
|
|
11
|
-
### sonic ecs
|
11
|
+
### sonic ecs exec
|
12
12
|
|
13
13
|
```sh
|
14
|
-
sonic ecs
|
14
|
+
sonic ecs exec [ECS_SERVICE] --cluster [ECS_CLUSTER]
|
15
15
|
```
|
16
16
|
|
17
17
|
Here's a concrete example:
|
18
18
|
|
19
19
|
```sh
|
20
|
-
sonic ecs
|
20
|
+
sonic ecs exec hi-web --cluster staging
|
21
21
|
```
|
22
22
|
|
23
23
|
You should see something like this:
|
24
24
|
|
25
25
|
```sh
|
26
|
-
$ sonic ecs
|
26
|
+
$ sonic ecs exec hi-web --cluster staging
|
27
27
|
Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
|
28
|
-
Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
|
29
28
|
=> ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-exec.sh
|
30
|
-
Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
|
31
29
|
root@fc4035f90bdc:/app#
|
32
30
|
```
|
33
31
|
|
@@ -38,7 +36,7 @@ What you see in the last line above is a bash prompt because you are in a bash s
|
|
38
36
|
Here are examples to show what is possible:
|
39
37
|
|
40
38
|
```
|
41
|
-
$ sonic ecs
|
39
|
+
$ sonic ecs exec hi-web bash
|
42
40
|
# You're in the docker container now
|
43
41
|
$ ls # check out some files to make sure you're the right place
|
44
42
|
$ ps auxxx | grep puma # is the web process up?
|
@@ -49,7 +47,7 @@ $ bundle exec rails c # start up a rails console to debug
|
|
49
47
|
You can also pass in bundle exec rails console if you want to get to that as quickly as possible.
|
50
48
|
|
51
49
|
```
|
52
|
-
$ sonic ecs
|
50
|
+
$ sonic ecs exec hi-web bundle exec rails console
|
53
51
|
# You're a rails console in the docker container now
|
54
52
|
> User.count
|
55
53
|
```
|
@@ -57,36 +55,34 @@ $ sonic ecs-exec hi-web-stag bundle exec rails console
|
|
57
55
|
You can also use the container instance id or instance id in place of the service name:
|
58
56
|
|
59
57
|
```
|
60
|
-
sonic ecs
|
61
|
-
sonic ecs
|
58
|
+
sonic ecs exec 9f1dadc7-4f67-41da-abec-ec08810bfbc9 bash
|
59
|
+
sonic ecs exec i-006a097bb10643e20 bash
|
62
60
|
```
|
63
61
|
|
64
|
-
### Settings -
|
62
|
+
### Settings - ecs_service_cluster_map
|
65
63
|
|
66
64
|
As mentioned in the [previous section]({% link _docs/tutorial-ssh.md %}) and also in the [Settings documentation]({% link _docs/settings.md %}) you can configure a `~/.sonic/settings.yml` file which shortens the command further. Let's add this to your settings:
|
67
65
|
|
68
66
|
```yaml
|
69
|
-
|
70
|
-
default:
|
71
|
-
hi-web
|
67
|
+
ecs_service_cluster_map:
|
68
|
+
default: staging
|
69
|
+
hi-web: staging
|
72
70
|
```
|
73
71
|
|
74
72
|
This makes the command consise and memorable.
|
75
73
|
|
76
74
|
```sh
|
77
|
-
sonic ecs
|
75
|
+
sonic ecs exec hi-web
|
78
76
|
```
|
79
77
|
|
80
78
|
The rest of this section assumes that you have the `~/.sonic/settings.yml` set up.
|
81
79
|
|
82
|
-
You can also tack on a command at the end of the `ecs
|
80
|
+
You can also tack on a command at the end of the `ecs exec` command to be run as a one off instead of starting a bash shell. Example:
|
83
81
|
|
84
82
|
```
|
85
|
-
$ sonic ecs
|
83
|
+
$ sonic ecs exec hi-web uname -a
|
86
84
|
Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
|
87
|
-
Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
|
88
85
|
=> ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-exec.sh uname -a
|
89
|
-
Warning: Permanently added '34.211.195.71' (ECDSA) to the list of known hosts.
|
90
86
|
Linux fc4035f90bdc 4.4.51-40.58.amzn1.x86_64 #1 SMP Tue Feb 28 21:57:17 UTC 2017 x86_64 GNU/Linux
|
91
87
|
Connection to 34.211.195.71 closed.
|
92
88
|
$
|
@@ -95,5 +91,5 @@ $
|
|
95
91
|
Remember the command runs within the running docker container.
|
96
92
|
|
97
93
|
<a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ssh.md %}">Back</a>
|
98
|
-
<a id="next" class="btn btn-primary" href="{% link _docs/tutorial-ecs-
|
94
|
+
<a id="next" class="btn btn-primary" href="{% link _docs/tutorial-ecs-sh.md %}">Next Step</a>
|
99
95
|
<p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
|
@@ -0,0 +1,73 @@
|
|
1
|
+
---
|
2
|
+
title: ECS Run
|
3
|
+
---
|
4
|
+
|
5
|
+
The nice thing about the previous `ecs exec` command we covered is that it allows you to get into the actual running container and debug with the exact environment that is on production. The cavaet with doing this is that we are affecting a live process that could be in actual use. If you do something inadvertently wrong on the server it could affect users. Sometimes it is nice to start up a new container with the exact same environment as the other running containers but be isolated so you cannot affect live requests.
|
6
|
+
|
7
|
+
The `sonic ecs sh` command is similar to the `sonic ecs exec` command except it'll run a brand new container with the same environment variables as the task associated with the service. This allows you to debug in a container with the exact environment variables as the running tasks/containers without affecting the live service. So this is safer since you will not be able to mess up a live container that is in service.
|
8
|
+
|
9
|
+
### sonic ecs sh
|
10
|
+
|
11
|
+
```sh
|
12
|
+
sonic ecs sh [ECS_SERVICE] --cluster [ECS_CLUSTER]
|
13
|
+
```
|
14
|
+
|
15
|
+
Here's an example:
|
16
|
+
|
17
|
+
```sh
|
18
|
+
sonic ecs sh hi-web
|
19
|
+
```
|
20
|
+
|
21
|
+
You see something like this:
|
22
|
+
|
23
|
+
```sh
|
24
|
+
$ sonic ecs sh hi-web
|
25
|
+
Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
|
26
|
+
=> ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-run.sh
|
27
|
+
+ exec docker exec -ti 385b643c7a895231d2b193574368b0c6c6bebce487267c3c175d0acea3082d4c bash
|
28
|
+
root@29e7c1253c46:/app#
|
29
|
+
$
|
30
|
+
```
|
31
|
+
|
32
|
+
You are now in a docker container running exactly the same environment as the other running containers with the `hi-web` service. While this looks similiar to the `ecs exec` command this container is a brand new process and is isolated from any live request. You can do whatever you want in this container and experiment to your heart's content.
|
33
|
+
|
34
|
+
We can prove that this is a brand new docker container that is outside of ECS' knowledge. Let's ssh into the same instance and take a look at all the running docker containers in another terminal.
|
35
|
+
|
36
|
+
```sh
|
37
|
+
$ sonic ssh hi-web docker ps
|
38
|
+
=> ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@34.211.195.71 docker ps
|
39
|
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
40
|
+
29e7c1253c46 tongueroo/hi:ufo-2017-06-13T14-48-08-0a9eea5 "bash" 54 seconds ago Up 53 seconds 3000/tcp cocky_goldstine
|
41
|
+
fc4035f90bdc tongueroo/hi:ufo-2017-06-13T14-48-08-0a9eea5 "bin/web" About an hour ago Up About an hour 0.0.0.0:32768->3000/tcp ecs-hi-web-11-web-9eb081978abad89a9701
|
42
|
+
bf646ae7789a amazon/amazon-ecs-agent:latest "/agent" About an hour ago Up About an hour ecs-agent
|
43
|
+
$
|
44
|
+
```
|
45
|
+
|
46
|
+
The output shows that there is this extra runnning container called `cocky_goldstine`. This name does not look like the typical ECS managed running docker container: `ecs-hi-web-11-web-9eb081978abad89a9701`. This is how we can tell that this is a container outside of ECS control.
|
47
|
+
|
48
|
+
```sh
|
49
|
+
$ sonic ecs sh hi-web bash
|
50
|
+
Running: scp -r /tmp/sonic ec2-user@34.211.195.71:/tmp/sonic > /dev/null
|
51
|
+
=> ssh -t ec2-user@34.211.195.71 bash /tmp/sonic/bash_scripts/docker-run.sh bash
|
52
|
+
root@29e7c1253c46:/app# exit
|
53
|
+
exit
|
54
|
+
Connection to 34.211.195.71 closed.
|
55
|
+
$
|
56
|
+
```
|
57
|
+
|
58
|
+
Let's exit out of the first terminal where you ran the original `sonic ecs sh` command and then list the running containers again.
|
59
|
+
|
60
|
+
```sh
|
61
|
+
$ sonic ssh hi-web docker ps
|
62
|
+
=> ssh -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null ec2-user@34.211.195.71 docker ps
|
63
|
+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
64
|
+
fc4035f90bdc tongueroo/hi:ufo-2017-06-13T14-48-08-0a9eea5 "bin/web" About an hour ago Up About an hour 0.0.0.0:32768->3000/tcp ecs-hi-web-11-web-9eb081978abad89a9701
|
65
|
+
bf646ae7789a amazon/amazon-ecs-agent:latest "/agent" About an hour ago Up About an hour ecs-agent
|
66
|
+
$
|
67
|
+
```
|
68
|
+
|
69
|
+
Zapped! The `cocky_goldstine` container that was created with `sonic ecs sh` is no more.
|
70
|
+
|
71
|
+
<a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-exec.md %}">Back</a>
|
72
|
+
<a id="next" class="btn btn-primary" href="{% link _docs/tutorial-execute.md %}">Next Step</a>
|
73
|
+
<p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
|
@@ -4,38 +4,68 @@ title: Sonic Execute
|
|
4
4
|
|
5
5
|
### Run One Liners
|
6
6
|
|
7
|
-
Sonic provides a way to execute commands remotely and securely across a list of AWS servers. It does this by leveraging [Amazon EC2 Run Command](https://aws.amazon.com/ec2/execute/). Sonic
|
7
|
+
Sonic provides a way to execute commands remotely and securely across a list of AWS servers. It does this by leveraging [Amazon EC2 Run Command](https://aws.amazon.com/ec2/execute/). Sonic a simple interface and some conveniences for you. The command is called `sonic execute`:
|
8
8
|
|
9
9
|
```sh
|
10
10
|
sonic execute [FILTER] [COMMAND]
|
11
11
|
```
|
12
12
|
|
13
|
-
Examples
|
13
|
+
## Examples Summary
|
14
14
|
|
15
15
|
```sh
|
16
|
-
sonic execute hi-web
|
16
|
+
sonic execute hi-web uptime
|
17
17
|
sonic execute hi-web-prod uptime
|
18
18
|
sonic execute i-030033c20c54bf149,i-030033c20c54bf150 uname -a
|
19
19
|
sonic execute i-030033c20c54bf149 file://hello.sh
|
20
20
|
```
|
21
21
|
|
22
|
-
|
22
|
+
## Example Detailed
|
23
23
|
|
24
|
-
|
25
|
-
sonic execute hi-web-stag yum install -y curl
|
26
|
-
```
|
27
|
-
|
28
|
-
The output of the command will show a useful `aws ssm list-commands` command to get status of the requested command.
|
24
|
+
Here's a command example output in detailed:
|
29
25
|
|
30
26
|
```sh
|
31
|
-
$ sonic execute
|
27
|
+
$ sonic execute i-0bf51a000ab4e73a8 uptime
|
28
|
+
Sending command to SSM with options:
|
29
|
+
---
|
30
|
+
instance_ids:
|
31
|
+
- i-0bf51a000ab4e73a8
|
32
|
+
document_name: AWS-RunShellScript
|
33
|
+
comment: sonic execute i-0bf51a000ab4e73a8 uptime
|
34
|
+
parameters:
|
35
|
+
commands:
|
36
|
+
- uptime
|
37
|
+
output_s3_region: us-east-1
|
38
|
+
output_s3_bucket_name: [reacted]
|
39
|
+
output_s3_key_prefix: ssm/commands/sonic
|
40
|
+
|
32
41
|
Command sent to AWS SSM. To check the details of the command:
|
33
|
-
aws ssm list-commands --command-id
|
34
|
-
|
42
|
+
aws ssm list-commands --command-id 0bb18d58-6436-49fd-9bfd-0c4b6c51c7a2
|
43
|
+
aws ssm get-command-invocation --command-id 0bb18d58-6436-49fd-9bfd-0c4b6c51c7a2 --instance-id i-0bf51a000ab4e73a8
|
44
|
+
|
45
|
+
Waiting for ssm command to finish.....
|
46
|
+
Command finished.
|
47
|
+
|
48
|
+
Displaying output for i-0bf51a000ab4e73a8.
|
49
|
+
Command status: Success
|
50
|
+
Command standard output:
|
51
|
+
01:08:10 up 8 days, 6:41, 0 users, load average: 0.00, 0.00, 0.00
|
52
|
+
|
53
|
+
To see the more output details visit:
|
54
|
+
https://us-west-2.console.aws.amazon.com/systems-manager/run-command/0bb18d58-6436-49fd-9bfd-0c4b6c51c7a2
|
55
|
+
|
56
|
+
Pro tip: the console url is already in your copy/paste clipboard.
|
35
57
|
$
|
36
58
|
```
|
37
59
|
|
38
|
-
|
60
|
+
Notice the conveniences of `sonic execute`, it:
|
61
|
+
|
62
|
+
1. Showed the parameters that will be sent as part of the send_command call to SSM.
|
63
|
+
2. Sent the command to SSM.
|
64
|
+
3. Waited for the command to finish.
|
65
|
+
4. Displayed the output of the command.
|
66
|
+
5. Provided the console url that visit to view more details about the SSM command.
|
67
|
+
|
68
|
+
The AWS SSM console looks like this:
|
39
69
|
|
40
70
|
<img src="/img/tutorials/ec2-console-run-command.png" class="doc-photo" />
|
41
71
|
|
@@ -43,13 +73,59 @@ The output of the commands ran are also showed in the EC2 Run Command Console.
|
|
43
73
|
|
44
74
|
The `sonic execute` command can understand a variety of different filters. The filters can be a list of instances ids or one EC2 tag value. Note, ECS service names are *not* supported for the filter.
|
45
75
|
|
46
|
-
Here is an example, where the uptime command will run on both i-030033c20c54bf149 and i-030033c20c54bf150 instances.
|
76
|
+
Here is an example, where the uptime command will run on both `i-030033c20c54bf149` and `i-030033c20c54bf150` instances.
|
47
77
|
|
48
78
|
```sh
|
49
79
|
sonic execute i-066b140d9479e9681,i-09482b1a6e330fbf7 uptime
|
50
80
|
```
|
51
81
|
|
52
|
-
|
82
|
+
## Windows Support
|
83
|
+
|
84
|
+
Windows is also supported. When running a command sonic will first attempt to use the `AWS-RunShellScript` run command, and if it detects that the instance's platform does not support `AWS-RunShellScript`, it will run the command with the `AWS-RunPowerShellScript` run command. Here's an example:
|
85
|
+
|
86
|
+
```
|
87
|
+
$ sonic execute i-0917ad61b10fa1059 pwd
|
88
|
+
Sending command to SSM with options:
|
89
|
+
---
|
90
|
+
instance_ids:
|
91
|
+
- i-0917ad61b10fa1059
|
92
|
+
document_name: AWS-RunShellScript
|
93
|
+
comment: sonic execute i-0917ad61b10fa1059 pwd
|
94
|
+
parameters:
|
95
|
+
commands:
|
96
|
+
- pwd
|
97
|
+
output_s3_region: us-east-1
|
98
|
+
output_s3_bucket_name: boltops-infra-stag
|
99
|
+
output_s3_key_prefix: ssm/commands/sonic
|
100
|
+
|
101
|
+
Cannot perform operation for instance id i-0917ad61b10fa1059 of platform type Windows
|
102
|
+
Retrying with document_name AWS-RunPowerShellScript
|
103
|
+
Retries: 1
|
104
|
+
Command sent to AWS SSM. To check the details of the command:
|
105
|
+
aws ssm list-commands --command-id 8a196058-445e-4960-9efb-be746ecf98dc
|
106
|
+
aws ssm get-command-invocation --command-id 8a196058-445e-4960-9efb-be746ecf98dc --instance-id i-0917ad61b10fa1059
|
107
|
+
|
108
|
+
Waiting for ssm command to finish......
|
109
|
+
Command finished.
|
110
|
+
|
111
|
+
Displaying output for i-0917ad61b10fa1059.
|
112
|
+
Command status: Success
|
113
|
+
Command standard output:
|
114
|
+
|
115
|
+
Path
|
116
|
+
----
|
117
|
+
C:\Windows\system32
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
To see the more output details visit:
|
122
|
+
https://us-east-1.console.aws.amazon.com/systems-manager/run-command/8a196058-445e-4960-9efb-be746ecf98dc
|
123
|
+
|
124
|
+
Pro tip: the console url is already in your copy/paste clipboard.
|
125
|
+
$
|
126
|
+
```
|
127
|
+
|
128
|
+
## Run Scripts
|
53
129
|
|
54
130
|
Sometimes you might want to run more than just a one-liner command. If you need to run a full script, you can provide the file path to the script by designating it with `file://`. For example, here's a file called `hi.sh`:
|
55
131
|
|
@@ -61,7 +137,7 @@ echo "hello world"
|
|
61
137
|
Here's how you run that file:
|
62
138
|
|
63
139
|
```sh
|
64
|
-
sonic execute hi-web
|
140
|
+
sonic execute hi-web file://hi.sh
|
65
141
|
```
|
66
142
|
|
67
143
|
The file gets read by `sonic execute` and sent to EC2 Run Command to be executed.
|
@@ -73,6 +149,6 @@ The `sonic execute` command relies on EC2 Run Manager. So you will need to have
|
|
73
149
|
* You can follow the [installation guide]({% link _docs/install.md %}) to install EC2 Run Manager.
|
74
150
|
* You can read on [Why EC2 Run Manager]({% link _docs/why-ec2-run-command.md %}) is used also.
|
75
151
|
|
76
|
-
<a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-
|
152
|
+
<a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-sh.md %}">Back</a>
|
77
153
|
<a id="next" class="btn btn-primary" href="{% link _docs/tutorial-list.md %}">Next Step</a>
|
78
154
|
<p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
|