Closed bugb closed 3 years ago
Hi @bugb,
Thanks for reaching out! I tried this as well and received the same error message. However, after creating a new task definition revision and selecting a Task Role, it worked. This can be done in the console by selecting your task definition and clicking on the Create new revision
option, or in the CLI by using the register-task-definition
command.
Hope this helps!
If we want to update for --enable-execute-command
which is currently not supported from AWS Management Console
Issue is closed but for anyone else coming here from google
You need to provide a "Task role" for a Task Definition (this is different than the "Task execution role"). This can be done by first going to IAM
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "ecs-tasks.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"ssmmessages:CreateControlChannel",
"ssmmessages:CreateDataChannel",
"ssmmessages:OpenControlChannel",
"ssmmessages:OpenDataChannel"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"logs:DescribeLogGroups"
],
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"logs:CreateLogStream",
"logs:DescribeLogStreams",
"logs:PutLogEvents"
],
"Resource": "arn:aws:logs:YOUR_REGION_HERE:YOUR_ACCOUNT_ID_HERE:log-group:/aws/ecs/CLUSTER_NAME:*"
}
]
}
enables execute command
aws ecs update-service --cluster CLUSTER_NAME --service SERVICE_NAME --region REGION --enable-execute-command --force-new-deployment
adds ARN to environment for easier cli. Does assume only 1 task running for the service, otherwise just manually go to ECS and grab arn and set them for your cli
TASK_ARN=$(aws ecs list-tasks --cluster CLUSTER_NAME --service SERVICE_NAME --region REGION --output text --query 'taskArns[0]')
see the task,
aws ecs describe-tasks --cluster CLUSTER_NAME --region REGION --tasks $TASK_ARN
exec in
aws ecs execute-command --region REGION --cluster CLUSTER_NAME --task $TASK_ARN --container CONTAINER --command "sh" --interactive
option2: if you are using jetbrains IDE, install plugin https://docs.aws.amazon.com/toolkit-for-jetbrains/latest/userguide/welcome.html
this plugin will help you to enables execute command and exec in
Thanks. I followed above and still got error. This was because I had an error in my event log on the service task.
Fix any and all event log errors first. It doesn't matter what the error is, even if it's a warning. In my case it was trying to connect to a port which my ec2 instance was also using - 80. I had to set my hostPort to 0 in the task definition. This fixed the error.
Ensure describe-tasks enableExecute is true
echo aws ecs describe-tasks --cluster $project_repo --region $REGION --tasks $taskARN --query="tasks[].enableExecuteCommand" --output text
Then I was able to see the tasks[].enableExecute=true. I can then: ecs execute-command successfully.
What commands can I run?
If I want to run sh commands I have to run it like this:
aws ecs execute-command --region $REGION --cluster $project_repo --task $taskARN --container $project_repo --interactive --command "/bin/sh -c 'cd /bin && ls'"
Ideally the solution though is to export the path.
Confirm by changing [ ] to [x] below:
Issue is about usage on:
--enable-execute-command
flagPlatform/OS/Hardware/Device What are you running the cli on?
Describe the question I want to update an ECS service to with
--enable-execute-command
flag but it is not success.Logs/output Get full traceback and error logs by adding
--debug
to the command.Command: