mirror of
https://github.com/jbranchaud/til
synced 2026-01-03 15:18:01 +00:00
Add SSH Into An ECS Container as an AWS TIL
This commit is contained in:
@@ -10,7 +10,7 @@ pairing with smart people at Hashrocket.
|
|||||||
|
|
||||||
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
For a steady stream of TILs, [sign up for my newsletter](https://crafty-builder-6996.ck.page/e169c61186).
|
||||||
|
|
||||||
_1600 TILs and counting..._
|
_1601 TILs and counting..._
|
||||||
|
|
||||||
See some of the other learning resources I work on:
|
See some of the other learning resources I work on:
|
||||||
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
- [Ruby Operator Lookup](https://www.visualmode.dev/ruby-operators)
|
||||||
@@ -111,6 +111,7 @@ See some of the other learning resources I work on:
|
|||||||
- [AWS CLI Requires Groff Executable](aws/aws-cli-requires-groff-executable.md)
|
- [AWS CLI Requires Groff Executable](aws/aws-cli-requires-groff-executable.md)
|
||||||
- [Find And Follow Server Logs](aws/find-and-follow-server-logs.md)
|
- [Find And Follow Server Logs](aws/find-and-follow-server-logs.md)
|
||||||
- [Sign Up User With Email And Password](aws/sign-up-user-with-email-and-password.md)
|
- [Sign Up User With Email And Password](aws/sign-up-user-with-email-and-password.md)
|
||||||
|
- [SSH Into An ECS Container](aws/ssh-into-an-ecs-container.md)
|
||||||
- [Use Specific AWS Profile With CLI](aws/use-specific-aws-profile-with-cli.md)
|
- [Use Specific AWS Profile With CLI](aws/use-specific-aws-profile-with-cli.md)
|
||||||
|
|
||||||
### Brew
|
### Brew
|
||||||
|
|||||||
50
aws/ssh-into-an-ecs-container.md
Normal file
50
aws/ssh-into-an-ecs-container.md
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
# SSH Into An ECS Container
|
||||||
|
|
||||||
|
In [Connect To Production Rails Console on AWS /
|
||||||
|
Flightcontrol](https://www.visualmode.dev/connect-to-production-rails-console-aws-flightcontrol),
|
||||||
|
I went into full detail about how to access `rails console` for a production
|
||||||
|
Rails app running in an ECS container.
|
||||||
|
|
||||||
|
A big part of that process was establishing an SSH connection to the ECS container.
|
||||||
|
|
||||||
|
To do that, I need to know my region, container ID, and task ID. I can get the
|
||||||
|
first two by listing my clusters and finding the cluster/container that houses
|
||||||
|
the Rails app.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ aws ecs list-clusters
|
||||||
|
{
|
||||||
|
"clusterArns": [
|
||||||
|
"arn:aws:ecs:us-east-2:123:cluster/rails-app-abc123"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The region then is `us-east-2` and the container ID is `rails-app-abc123`.
|
||||||
|
|
||||||
|
I can use that to find the task ID:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ aws ecs list-tasks --region us-east-2 --cluster rails-app-abc123
|
||||||
|
{
|
||||||
|
"taskArns": [
|
||||||
|
"arn:aws:ecs:us-east-2:123:task/rails-app-abc123/8526b3191d103bb1ff90c65a655ad004"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The task ID is the final portion of the URL:
|
||||||
|
`8526b3191d103bb1ff90c65a655ad004`.
|
||||||
|
|
||||||
|
Putting this all together I can SSH into the ECS container with a bash profile
|
||||||
|
like so:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
$ aws ecs execute-command \
|
||||||
|
--region us-east-2 \
|
||||||
|
--cluster rails-app-abc123 \
|
||||||
|
--container rails-app-abc123 \
|
||||||
|
--task 8526b3191d103bb1ff90c65a655ad004 \
|
||||||
|
--interactive \
|
||||||
|
--command "/bin/bash"
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user