You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update README to include information on connecting to rails console via aws ecs execute-command (#55)
* Update README to include information on connecting to rails console via aws ecs execute-command
* Add shell script for ssh-ing into staging/prod
* Clean up
* Update README describing the best way to access dev console on staging/prod
* Fix typos
* Clean up
* Update brakeman
* Changes based on PR review
Copy file name to clipboardExpand all lines: README.md
+60-2Lines changed: 60 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -79,10 +79,68 @@ Locally, you can use `bin/rails console`
79
79
80
80
On Heroku, you can use `heroku run rails c -a <review-app-name>`
81
81
82
-
On Staging and Production, you'll have to utilize AWS Query Editor or `aws rds-data` commands to access the database.
82
+
On Staging and Production, use the `aws ecs execute-command`. You must have `awscli` isntalled on your machine already (check with `aws --version`).
83
+
If not, `brew install awscli` on your local machine ([AWS instructions here](https://docs.aws.amazon.com/cli/latest/userguide/getting-started-install.html)).
84
+
Please download the [AWS Session Manager as well following AWS instructions](https://docs.aws.amazon.com/systems-manager/latest/userguide/install-plugin-macos-overview.html)
85
+
86
+
You also need `AWS_PROFILE` for Prior Year Access (for both Prod and Non-Prod AWS accounts). [Follow AWS Identity Center: Configuring SSO instructions](https://www.notion.so/cfa/AWS-Identity-Center-e8a28122b2f44595a2ef56b46788ce2c?source=copy_link#ef1c6c77703b4215bbe1953de4692054) to configure your profile correctly.
87
+
Name the Prior Year Access - Prod profile as `pya-prod` and Prior Year Access - Non-prod profile as `pya-nonprod`. You can rename your aws profile by editing your `~/.aws/config` and `~/.aws/credentials`.
88
+
89
+
### Use bin/ecs_exec script (recommended in most cases)
90
+
91
+
1. Make sure you're logged into aws: `aws sso login`. This should open up an AWS console and have you sign in (if you aren't signed in already). After verification, it'll return you to the terminal
92
+
2. For staging, you can use `bin/ecs_exec`
93
+
3. For production, you can pass in `bin/ecs_exec --environment production`
94
+
4. You can pass in other parameters like:
95
+
1.`--desired-status`: `RUNNING` by default, but can specify `STOPPED`. See documentation for [list-tasks](https://docs.aws.amazon.com/cli/latest/reference/ecs/list-tasks.html).
96
+
2.`--command`: if you want to run something other than `bin/sh`
97
+
3. There are other commands that the aws ecs can call. The options can be passed manually into the `list-tasks` ([doc](https://docs.aws.amazon.com/cli/latest/reference/ecs/list-tasks.html)) and `execute-command`([doc](https://docs.aws.amazon.com/cli/latest/reference/ecs/execute-command.html)) commands. See linked documentation.
98
+
5. Type in `bin/rails c --sandbox` (remove `--sandbox` if you must perform operations that will write/modify data in the db; please pair/try to be loud as possible when performing a write operation)
99
+
1. When you start rails console, it will say `Loading production environment (Rails <version>)` for both staging AND production. This is because we don't explicitly set a `staging` environment for the RAILS_ENV in our app, to make sure that the environments are similar as possible (We use `REVIEW_APP` to specify heroku/staging environments against the production environment).
100
+
101
+
---
102
+
103
+
### Ssh into AWS ECS Manually (if you need to pass in more parameters than the script supports)
104
+
105
+
1. Find your `task ARN`
106
+
```
107
+
AWS_PROFILE=<aws profile name> \
108
+
aws ecs list-tasks --cluster pya-staging-web \
109
+
--query "taskArns[0]" --output text
110
+
```
111
+
This will return the RUNNING task.
112
+
113
+
Note that if the newest deploy ran into trouble starting the task, it will be in the STOPPED state. In order to try to debug tasks that have not started successfully or have died/finished, you can add in `--desired-status STOPPED`
114
+
See [AWS CLI list-tasks docs for more information and options](https://docs.aws.amazon.com/cli/latest/reference/ecs/list-tasks.html#options)
115
+
116
+
2. Run the `aws ecs execute-command` ([AWS ECS Execute-Command Docs](https://docs.aws.amazon.com/cli/latest/reference/ecs/execute-command.html))
0 commit comments