27
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

awscli ECS 関連コマンドメモ

Posted at

主にコピペ用。

コマンドメモ

### 0. 環境変数
# CLUSTER_NAME_OR_ARN はそれぞれの環境に合わせて書き換えること
export CLUSTER_NAME_OR_ARN=<ECSクラスター名またはARN>

### 1. ヘルプ表示
aws ecs help
aws ecs <COMMAND> help

### 2. ECSクラスター一覧表示
aws ecs list-clusters
aws ecs list-clusters --output text 
aws ecs list-clusters --output text | sed -e 's/\s/ /g' | cut -d ' ' -f2

### 3. ECSクラスター詳細表示
aws ecs describe-clusters --cluster $CLUSTER_NAME_OR_ARN
aws ecs describe-clusters --cluster $CLUSTER_NAME_OR_ARN --output text

# ECSクラスターは --cluster または --clusters オプションにてスペース区切りで列挙することで複数指定可能
# 例: 
# aws ecs describe-clusters --clusters <CLUSTER_NAME_OR_ARN> <CLUSTER_NAME_OR_ARN2> <CLUSTER_NAME_OR_ARN3> ...

### 4. ECSサービス一覧表示
aws ecs list-services --cluster $CLUSTER_NAME_OR_ARN
aws ecs list-services --cluster $CLUSTER_NAME_OR_ARN --output text
aws ecs list-services --cluster $CLUSTER_NAME_OR_ARN --output text | sed -e 's/\s/ /g' | cut -d ' ' -f2

#### 4.1. ECSサービスARN環境変数セット
export ECS_SERVICE_ARN=arn:aws:ecs:<REGION>:<ACCOUNT_ID>:service/<SERVICE_NAME>
# or
export ECS_SERVICE_NAME=<ECSサービス名>
export ECS_SERVICE_ARN="$(aws ecs list-services --cluster $CLUSTER_NAME_OR_ARN --output text | sed -e 's/\s/ /g' | cut -d ' ' -f2 |grep $ECS_SERVICE_NAME)"

### 5. ECSサービス詳細表示
aws ecs describe-services --cluster $CLUSTER_NAME_OR_ARN --services $ECS_SERVICE_ARN

### 6. ECSタスク一覧表示
aws ecs list-tasks --cluster $CLUSTER_NAME_OR_ARN --service-name $ECS_SERVICE_ARN
aws ecs list-tasks --cluster $CLUSTER_NAME_OR_ARN --service-name $ECS_SERVICE_ARN --output text
aws ecs list-tasks --cluster $CLUSTER_NAME_OR_ARN --service-name $ECS_SERVICE_ARN --output text | sed -e 's/\s/ /g' | cut -d ' ' -f2

#### 6.1 ECSタスク環境変数セット
export ECS_TASK_ARNS="$(aws ecs list-tasks --cluster $CLUSTER_NAME_OR_ARN --service-name $ECS_SERVICE_ARN --output text | sed -e 's/\s/ /g' | cut -d ' ' -f2 | tr '\n' ' ')"

### 7. ECSタスク詳細表示
aws ecs describe-tasks --cluster $CLUSTER_NAME_OR_ARN --tasks $(echo $ECS_TASK_ARNS)
aws ecs describe-tasks --cluster $CLUSTER_NAME_OR_ARN --tasks $(echo $ECS_TASK_ARNS) --output text

随時追加予定。

参考

27
29
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
27
29

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?