sonic-screwdriver 1.4.0 → 2.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/bin/commit_docs.sh +26 -0
  3. data/.circleci/config.yml +72 -0
  4. data/.gitignore +2 -1
  5. data/CHANGELOG.md +29 -3
  6. data/Gemfile +3 -3
  7. data/Guardfile +17 -10
  8. data/LICENSE.txt +2 -2
  9. data/README.md +25 -28
  10. data/Rakefile +9 -2
  11. data/docs/_config.yml +3 -0
  12. data/docs/_docs/help.md +1 -1
  13. data/docs/_docs/install-bastion.md +5 -15
  14. data/docs/_docs/install.md +3 -13
  15. data/docs/_docs/next-steps.md +1 -1
  16. data/docs/_docs/settings.md +42 -56
  17. data/docs/_docs/tutorial-ecs-exec.md +16 -20
  18. data/docs/_docs/tutorial-ecs-sh.md +73 -0
  19. data/docs/_docs/tutorial-execute.md +106 -38
  20. data/docs/_docs/tutorial-ssh.md +15 -19
  21. data/docs/_docs/why-ec2-run-command.md +1 -1
  22. data/docs/_includes/commands.html +5 -5
  23. data/docs/_includes/content.html +5 -0
  24. data/docs/_includes/css/main.css +15 -9
  25. data/docs/_includes/css/sonic.css +7 -5
  26. data/docs/_includes/example.html +4 -4
  27. data/docs/_includes/footer.html +6 -4
  28. data/docs/_includes/reference.md +1 -0
  29. data/docs/_includes/subnav.html +2 -1
  30. data/docs/_reference/sonic-completion.md +44 -0
  31. data/docs/_reference/sonic-completion_script.md +25 -0
  32. data/docs/_reference/sonic-ecs-exec.md +30 -0
  33. data/docs/_reference/sonic-ecs-help.md +21 -0
  34. data/docs/_reference/sonic-ecs-sh.md +35 -0
  35. data/docs/_reference/sonic-ecs.md +25 -0
  36. data/docs/_reference/sonic-execute.md +85 -0
  37. data/docs/_reference/sonic-list.md +40 -0
  38. data/docs/_reference/sonic-ssh.md +86 -0
  39. data/docs/_reference/sonic-version.md +21 -0
  40. data/docs/bin/web +1 -1
  41. data/docs/img/tutorials/ec2-console-run-command.png +0 -0
  42. data/docs/quick-start.md +17 -22
  43. data/docs/reference.md +12 -0
  44. data/{bin → exe}/sonic +3 -3
  45. data/lib/bash_scripts/docker-exec.sh +1 -0
  46. data/lib/bash_scripts/docker-run.sh +8 -1
  47. data/lib/sonic.rb +11 -3
  48. data/lib/sonic/{aws_services.rb → aws_service.rb} +6 -1
  49. data/lib/sonic/base_command.rb +82 -0
  50. data/lib/sonic/checks.rb +2 -2
  51. data/lib/sonic/cli.rb +41 -29
  52. data/lib/sonic/command.rb +8 -22
  53. data/lib/sonic/completer.rb +161 -0
  54. data/lib/sonic/completer/script.rb +6 -0
  55. data/lib/sonic/completer/script.sh +10 -0
  56. data/lib/sonic/core.rb +15 -0
  57. data/lib/sonic/default/settings.yml +9 -16
  58. data/lib/sonic/docker.rb +30 -2
  59. data/lib/sonic/ecs.rb +22 -0
  60. data/lib/sonic/execute.rb +203 -51
  61. data/lib/sonic/help.rb +9 -0
  62. data/lib/sonic/help/command/send.md +10 -0
  63. data/lib/sonic/help/completion.md +22 -0
  64. data/lib/sonic/help/completion_script.md +3 -0
  65. data/lib/sonic/help/ecs/exec.md +8 -0
  66. data/lib/sonic/help/ecs/sh.md +13 -0
  67. data/lib/sonic/help/execute.md +59 -0
  68. data/lib/sonic/help/list.md +17 -0
  69. data/lib/sonic/help/ssh.md +60 -0
  70. data/lib/sonic/list.rb +5 -2
  71. data/lib/sonic/setting.rb +47 -0
  72. data/lib/sonic/ssh.rb +42 -23
  73. data/lib/sonic/ssh/identifier_detector.rb +7 -3
  74. data/lib/sonic/ui.rb +2 -2
  75. data/lib/sonic/version.rb +1 -1
  76. data/sonic.gemspec +14 -9
  77. data/spec/lib/cli_spec.rb +11 -11
  78. data/spec/lib/sonic/execute_spec.rb +1 -2
  79. data/spec/spec_helper.rb +18 -10
  80. metadata +115 -19
  81. data/Gemfile.lock +0 -134
  82. data/docs/_docs/tutorial-ecs-run.md +0 -100
  83. data/lib/sonic/cli/help.rb +0 -152
  84. data/lib/sonic/settings.rb +0 -115
@@ -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-exec
11
+ ### sonic ecs exec
12
12
 
13
13
  ```sh
14
- sonic ecs-exec [ECS_SERVICE] --cluster [ECS_CLUSTER]
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-exec hi-web-stag --cluster stag
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-exec hi-web-stag --cluster stag
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-exec hi-web-stag bash
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-exec hi-web-stag bundle exec rails console
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-exec 9f1dadc7-4f67-41da-abec-ec08810bfbc9 bash
61
- sonic ecs-exec i-006a097bb10643e20 bash
58
+ sonic ecs exec 9f1dadc7-4f67-41da-abec-ec08810bfbc9 bash
59
+ sonic ecs exec i-006a097bb10643e20 bash
62
60
  ```
63
61
 
64
- ### Settings - service_cluster mapping
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
- service_cluster:
70
- default: stag
71
- hi-web-stag: stag
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-exec hi-web-stag
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-exec` command to be run as a one off instead of starting a bash shell. Example:
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-exec hi-web-stag uname -a
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-run.md %}">Next Step</a>
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,65 +4,133 @@ 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 hides any complexity and provides a simple interface for you. The command is called `sonic execute`:
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
- ```sh
10
- sonic execute [FILTER] [COMMAND]
11
- ```
9
+ sonic execute [FILTER] [COMMAND]
12
10
 
13
- Examples:
11
+ ## Examples Summary
14
12
 
15
- ```sh
16
- sonic execute hi-web-stag uptime
17
- sonic execute hi-web-prod uptime
18
- sonic execute i-030033c20c54bf149,i-030033c20c54bf150 uname -a
19
- sonic execute i-030033c20c54bf149 file://hello.sh
20
- ```
13
+ sonic execute --tags Name=demo-web uptime
14
+ sonic execute --tags Name=demo-web,demo-worker uptime # multiple tag values
15
+ sonic execute --instance-ids i-030033c20c54bf149,i-030033c20c54bf150 uname -a
16
+ sonic execute --instance-ids i-030033c20c54bf149 file://hello.sh
21
17
 
22
- Let's do something more useful:
18
+ ## Example Detailed
23
19
 
24
- ```sh
25
- sonic execute hi-web-stag yum install -y curl
26
- ```
20
+ Here's a command example output in detailed:
27
21
 
28
- The output of the command will show a useful `aws ssm list-commands` command to get status of the requested command.
22
+ $ sonic execute --instance-ids i-0bf51a000ab4e73a8 uptime
23
+ Sending command to SSM with options:
24
+ ---
25
+ instance_ids:
26
+ - i-0bf51a000ab4e73a8
27
+ document_name: AWS-RunShellScript
28
+ comment: sonic execute --instance-ids i-0bf51a000ab4e73a8 uptime
29
+ parameters:
30
+ commands:
31
+ - uptime
32
+ output_s3_region: us-east-1
33
+ output_s3_bucket_name: [reacted]
34
+ output_s3_key_prefix: ssm/commands/sonic
29
35
 
30
- ```sh
31
- $ sonic execute hi-web-stag uptime
32
- Command sent to AWS SSM. To check the details of the command:
33
- aws ssm list-commands --command-id 4133e5eb-aa18-40dd-be25-a176eb15e515
34
- Pro tip: the aws ssm command is already in your copy/paste clipboard.
35
- $
36
- ```
36
+ Command sent to AWS SSM. To check the details of the command:
37
+ aws ssm list-commands --command-id 0bb18d58-6436-49fd-9bfd-0c4b6c51c7a2
38
+ aws ssm get-command-invocation --command-id 0bb18d58-6436-49fd-9bfd-0c4b6c51c7a2 --instance-id i-0bf51a000ab4e73a8
39
+
40
+ Waiting for ssm command to finish.....
41
+ Command finished.
42
+
43
+ Displaying output for i-0bf51a000ab4e73a8.
44
+ Command status: Success
45
+ Command standard output:
46
+ 01:08:10 up 8 days, 6:41, 0 users, load average: 0.00, 0.00, 0.00
37
47
 
38
- The output of the commands ran are also showed in the EC2 Run Command Console. Here's an example:
48
+ To see the more output details visit:
49
+ https://us-west-2.console.aws.amazon.com/systems-manager/run-command/0bb18d58-6436-49fd-9bfd-0c4b6c51c7a2
50
+
51
+ Pro tip: the console url is already in your copy/paste clipboard.
52
+ $
53
+
54
+ Notice the conveniences of `sonic execute`, it:
55
+
56
+ 1. Showed the parameters that will be sent as part of the send_command call to SSM.
57
+ 2. Sent the command to SSM.
58
+ 3. Waited for the command to finish.
59
+ 4. Displayed the output of the command.
60
+ 5. Provided the console url that visit to view more details about the SSM command.
61
+
62
+ The AWS SSM console looks like this:
39
63
 
40
64
  <img src="/img/tutorials/ec2-console-run-command.png" class="doc-photo" />
41
65
 
42
- ### Polymorphic Filter
66
+ ### Filter Options
67
+
68
+ The `sonic execute` command can understand a variety of different filters: `--tags` and `--instance-ids`. Note, ECS service names are *not* supported for the filter.
69
+
70
+ Here is an example, where the uptime command will run on both `i-030033c20c54bf149` and `i-030033c20c54bf150` instances.
71
+
72
+ sonic execute --instance-ids i-066b140d9479e9681,i-09482b1a6e330fbf7 uptime
43
73
 
44
- 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.
74
+ Here is an example, where the uptime command will run on instances tagged with `Name=demo-web`
45
75
 
46
- Here is an example, where the uptime command will run on both i-030033c20c54bf149 and i-030033c20c54bf150 instances.
76
+ sonic execute --tags Name=demo-web uptime
77
+
78
+ ## Windows Support
79
+
80
+ 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:
47
81
 
48
- ```sh
49
- sonic execute i-066b140d9479e9681,i-09482b1a6e330fbf7 uptime
50
82
  ```
83
+ $ sonic execute --instance-ids i-0917ad61b10fa1059 pwd
84
+ Sending command to SSM with options:
85
+ ---
86
+ instance_ids:
87
+ - i-0917ad61b10fa1059
88
+ document_name: AWS-RunShellScript
89
+ comment: sonic execute --instance-ids i-0917ad61b10fa1059 pwd
90
+ parameters:
91
+ commands:
92
+ - pwd
93
+ output_s3_region: us-east-1
94
+ output_s3_bucket_name: boltops-infra-stag
95
+ output_s3_key_prefix: ssm/commands/sonic
96
+
97
+ Cannot perform operation for instance id i-0917ad61b10fa1059 of platform type Windows
98
+ Retrying with document_name AWS-RunPowerShellScript
99
+ Retries: 1
100
+ Command sent to AWS SSM. To check the details of the command:
101
+ aws ssm list-commands --command-id 8a196058-445e-4960-9efb-be746ecf98dc
102
+ aws ssm get-command-invocation --command-id 8a196058-445e-4960-9efb-be746ecf98dc --instance-id i-0917ad61b10fa1059
103
+
104
+ Waiting for ssm command to finish......
105
+ Command finished.
106
+
107
+ Displaying output for i-0917ad61b10fa1059.
108
+ Command status: Success
109
+ Command standard output:
110
+
111
+ Path
112
+ ----
113
+ C:\Windows\system32
51
114
 
52
- ### Run Scripts
53
115
 
54
- 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
116
 
56
- ```bash
57
- #!/bin/bash
58
- echo "hello world"
117
+ To see the more output details visit:
118
+ https://us-east-1.console.aws.amazon.com/systems-manager/run-command/8a196058-445e-4960-9efb-be746ecf98dc
119
+
120
+ Pro tip: the console url is already in your copy/paste clipboard.
121
+ $
59
122
  ```
60
123
 
124
+ ## Run Scripts
125
+
126
+ 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`:
127
+
128
+ #!/bin/bash
129
+ echo "hello world"
130
+
61
131
  Here's how you run that file:
62
132
 
63
- ```sh
64
- sonic execute hi-web-stag file://hi.sh
65
- ```
133
+ sonic execute demo-web file://hi.sh
66
134
 
67
135
  The file gets read by `sonic execute` and sent to EC2 Run Command to be executed.
68
136
 
@@ -73,6 +141,6 @@ The `sonic execute` command relies on EC2 Run Manager. So you will need to have
73
141
  * You can follow the [installation guide]({% link _docs/install.md %}) to install EC2 Run Manager.
74
142
  * You can read on [Why EC2 Run Manager]({% link _docs/why-ec2-run-command.md %}) is used also.
75
143
 
76
- <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-run.md %}">Back</a>
144
+ <a id="prev" class="btn btn-basic" href="{% link _docs/tutorial-ecs-sh.md %}">Back</a>
77
145
  <a id="next" class="btn btn-primary" href="{% link _docs/tutorial-list.md %}">Next Step</a>
78
146
  <p class="keyboard-tip">Pro tip: Use the <- and -> arrow keys to move back and forward.</p>
@@ -2,8 +2,6 @@
2
2
  title: SSH
3
3
  ---
4
4
 
5
- ### SSH
6
-
7
5
  Sonic allows you to ssh into an instance quickly.
8
6
 
9
7
  Often when working with AWS EC2 it is helpful to ssh into an instance to debug. To ssh into an instance, the first thing you do is go to the EC2 Console and grab the public IP address.
@@ -32,7 +30,7 @@ The above command effectively translates to:
32
30
  ssh ec2-user@52.24.216.170
33
31
  ```
34
32
 
35
- By default the user that sonic uses to log in to the server is `ec2-user`. You can override the user easily like so:
33
+ By default the user that sonic uses to log in to the server is `ec2-user`. You can override the user as part of the sonic command like so:
36
34
 
37
35
  ```sh
38
36
  sonic ssh ubuntu@i-0f7f833131a51ce35
@@ -41,22 +39,23 @@ sonic ssh ubuntu@i-0f7f833131a51ce35
41
39
  The default user can also be configured with a `~/.sonic/settings.yml` or the project's `.sonic/settings.yml` file like so:
42
40
 
43
41
  ```yaml
44
- user: ec2-user
42
+ ssh:
43
+ user: ec2-user
45
44
  ```
46
45
 
47
46
  More information about sonic settings in available in the docs: [Settings]({% link _docs/settings.md %}).
48
47
 
49
48
  ### Polymorphic Identifiers
50
49
 
51
- The `sonic ssh` command can auto-detect the proper IP address with a variety of different identifiers. The identifier is not just limited to the instance id. The identifier can also be an EC2 tag-value filter, ECS service name, ECS container id or ECS task id.
50
+ The `sonic ssh` command can auto-detect the proper IP address with a variety of different identifiers. The identifier is not limited to the instance id. The identifier can be an EC2 tag-value filter, ECS service name, ECS container id or ECS task id.
52
51
 
53
52
  Polymorphic identifiers are convenient in case you happen to be on a dashboard with another identifier close by and handy. Here are examples of identifiers that `sonic ssh` understands.
54
53
 
55
54
  ```
56
55
  sonic ssh EC2_TAG_FILTER
57
- sonic ssh ECS_SERVICE --cluster stag
58
- sonic ssh ECS_CONTAINER_ID --cluster stag
59
- sonic ssh ECS_TASK_ID --cluster stag
56
+ sonic ssh ECS_SERVICE --cluster staging
57
+ sonic ssh ECS_CONTAINER_ID --cluster staging
58
+ sonic ssh ECS_TASK_ID --cluster staging
60
59
  ```
61
60
 
62
61
  The EC2 tag filter uses the 'tag-value' filter as described in the [AWS describe-instances](http://docs.aws.amazon.com/cli/latest/reference/ec2/describe-instances.html) filter docs. This filter is independent of the tag-key filter, which means any EC2 tag value will match, regardless of the tag key name. Sonic does not support spaces in the EC2 tag filter.
@@ -64,14 +63,11 @@ The EC2 tag filter uses the 'tag-value' filter as described in the [AWS describe
64
63
  Notice, that when the `sonic ssh` is passed an ECS identifier then it also requires the ECS cluster name. The commands above with the ECS identifier are normally shorten further by configuring the a [settings]({% link _docs/settings.md %}) file. Here's an example:
65
64
 
66
65
  ```yaml
67
- service_cluster:
66
+ ecs_service_cluster_map:
68
67
  default: my-default-cluster
69
- hi-web-prod: prod
70
- hi-clock-prod: prod
71
- hi-worker-prod: prod
72
- hi-web-stag: stag
73
- hi-clock-stag: stag
74
- hi-worker-stag: stag
68
+ hi-web: production
69
+ hi-clock: production
70
+ hi-worker: production
75
71
  ```
76
72
 
77
73
  With these settings in place, the ECS identifier commands get shortened to become:
@@ -82,16 +78,16 @@ sonic ssh ECS_SERVICE
82
78
  sonic ssh ECS_TASK_ID
83
79
  ```
84
80
 
85
- It then becomes effortless to ssh into an EC2 Container Instance with the ECS service name. For example, if the ECS service name is `hi-web-stag` then the command becomes.
81
+ It then becomes effortless to ssh into an EC2 Container Instance with the ECS service name. For example, if the ECS service name is `hi-web` then the command becomes.
86
82
 
87
83
  ```sh
88
- $ sonic ssh hi-web-stag
84
+ $ sonic ssh hi-web
89
85
  # now you are on the container instance
90
86
  $ docker ps
91
87
  $ curl -s http://localhost:51678/v1/meta | jq .
92
88
  ```
93
89
 
94
- The `hi-web-stag` can be running on multiple container instances. The `sonic ssh` command chooses the first container instance that it finds. If you need to ssh into a specific container instance, then use the `sonic ssh` command with an instance id instead.
90
+ The `hi-web` can be running on multiple container instances. The `sonic ssh` command chooses the first container instance that it finds. If you need to ssh into a specific container instance, then use the `sonic ssh` command with an instance id instead.
95
91
 
96
92
  You can also use the ECS container instance arn or task id to ssh into the machine. Examples:
97
93
 
@@ -120,7 +116,7 @@ Can't ssh into the server yet. Retrying until success.
120
116
 
121
117
  ### Specifying Custom Pem or Private Keys
122
118
 
123
- It is recommended that you use ssh-agent to specify a custom private key, covered here [3 SSH tips: Ssh-agent, Tunnel, and Escaping from the Dead](https://blog.boltops.com/2017/09/21/3-ssh-tips-ssh-agent-tunnel-and-escaping-from-the-dead). You can specify the private key if you prefer with the `-i` option though. Example:
119
+ It is recommended that you use ssh-agent to specify a custom private key, covered here [3 SSH tips: Ssh-agent, Tunnel, and Escaping from the Dead](https://blog.boltops.com/2017/09/21/3-ssh-tips-ssh-agent-tunnel-and-escaping-from-the-dead). But you can specify the private key if you prefer with the `-i` option though. Example:
124
120
 
125
121
  ```sh
126
122
  $ sonic ssh -i ~/.ssh/id_rsa-custom i-0b21da68fff89937b
@@ -9,7 +9,7 @@ Why use Amazon EC2 Run Command vs just using a multi-ssh session?
9
9
  * The EC2 Run Manager has the ability to run the command in "blue/green" fashion with concurrency controls. Say you have 100 servers, you can tell EC2 Run Manager to run the command on one server first and the expodentially roll it out to the rest of the servers until the command has successfully ran on all servers. If it the command errors on one server then it halts execution and does not run on the rest of the servers.
10
10
  * This is all provided for free by using EC2 Run Manager.
11
11
 
12
- The iniitial ertia of setting up EC2 Run Manager is actually very little. The [installation instructions]({% link _docs/install.md %}) demonstrate that installing EC2 Run Manager is literally one command.
12
+ The initial ertia of setting up EC2 Run Manager is actually very little. The [installation instructions]({% link _docs/install.md %}) demonstrate that installing EC2 Run Manager is literally one command.
13
13
 
14
14
  <a id="prev" class="btn btn-basic" href="{% link _docs/why.md %}">Back</a>
15
15
  <a id="next" class="btn btn-primary" href="{% link _docs/how-it-works.md %}">Next Step</a>