-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0efc55f
commit 0617525
Showing
14 changed files
with
164 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
7275449c40b54d9dc82679a0f7a5a5b26d721193 | ||
cab4c662c7e7e9f659749848d1692e874ac7b62f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
# Running commands on the service | ||
|
||
The infrastructure supports developer access to a running application's service container using [ECS Exec](https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html). You can run commands in or get a shell to an actively running container, allowing you to quickly debug issues or to use the container to access an attached database. Once you create an interactive shell, you will be operating with the same permissions as the container (e.g. you may access any database the container has access to, but you cannot access databases within the same account that the container does not have access to). | ||
|
||
⚠️ **Warning: It is not recommended to enable service access in a production environment!** | ||
|
||
## Prerequisites | ||
|
||
* You'll need to have [set up infrastructure tools](./set-up-infrastructure-tools.md), like Terraform, AWS CLI, and AWS authentication | ||
* You'll need to have set up the [app environments](./set-up-app-env.md) | ||
* You'll need to have [installed the Session Manager plugin for the AWS CLI](https://docs.aws.amazon.com/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html) | ||
|
||
## Instructions | ||
|
||
### 1. Make sure you're authenticated into the AWS account that the ECS container is running in | ||
|
||
This takes effect in whatever account you're authenticated into. To see which account that is, run | ||
|
||
```bash | ||
aws sts get-caller-identity | ||
``` | ||
|
||
To see a more human readable account alias instead of the account, run | ||
|
||
```bash | ||
aws iam list-account-aliases | ||
``` | ||
|
||
### 2. Enable service execution access | ||
|
||
Within the `app-config` directory (e.g. `infra/<APP_NAME>/app-config`), each environment has its own config file named after the environment. For example, if the application has three environments `dev`, `staging`, and `prod`, it should have corresponding `dev.tf`, `staging.tf`, and `prod.tf` files. | ||
|
||
In the environment config file for the environment that you want to enable service access, set `enable_command_execution` to `true`. | ||
|
||
### 3. Update the network | ||
|
||
To enable service execution access, the VPC requires an additional VPC endpoint. Update the network by running | ||
|
||
```bash | ||
make infra-update-network NETWORK_NAME=<NETWORK_NAME> | ||
``` | ||
|
||
`ENVIRONMENT` needs to be the name of the network that the application environment is running in. | ||
|
||
### 4. Update the application service | ||
|
||
To enable service execution access, some configuration changes need to be applied to the ECS Task Definition. Update the service by running | ||
|
||
```bash | ||
make infra-update-app-service APP_NAME=<APP_NAME> ENVIRONMENT=<ENVIRONMENT> | ||
``` | ||
|
||
`APP_NAME` needs to be the name of the application folder within the `infra` folder. | ||
|
||
`ENVIRONMENT` needs to be the name of the environment to update. | ||
|
||
### 5. Execute commands | ||
|
||
To create an interactive shell, run | ||
|
||
```bash | ||
aws ecs execute-command --cluster <CLUSTER_NAME> \ | ||
--task <TASK_ID> \ | ||
--container <CONTAINER_NAME> \ | ||
--interactive \ | ||
--command "/bin/sh" | ||
``` | ||
|
||
To run other commands, modify the `--command` flag to execute the command, rather than starting a shell. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#----------------- | ||
# ECS Exec Access | ||
# See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html | ||
#----------------- | ||
resource "aws_iam_policy" "ecs_exec" { | ||
name = "${var.service_name}-ecs-exec" | ||
description = "Allow access to SSM Messages to support ECS Exec" | ||
policy = data.aws_iam_policy_document.ecs_exec.json | ||
} | ||
|
||
data "aws_iam_policy_document" "ecs_exec" { | ||
# Allow ECS to access SSM Messages so that ECS Exec works | ||
# See https://docs.aws.amazon.com/AmazonECS/latest/developerguide/ecs-exec.html | ||
statement { | ||
sid = "SSMAccess" | ||
effect = "Allow" | ||
actions = [ | ||
"ssmmessages:CreateControlChannel", | ||
"ssmmessages:CreateDataChannel", | ||
"ssmmessages:OpenControlChannel", | ||
"ssmmessages:OpenDataChannel", | ||
] | ||
resources = ["*"] | ||
} | ||
} | ||
|
||
resource "aws_iam_role_policy_attachment" "ecs_exec" { | ||
count = var.enable_command_execution ? 1 : 0 | ||
role = aws_iam_role.app_service.name | ||
policy_arn = aws_iam_policy.ecs_exec.arn | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters