Skip to content

Instantly share code, notes, and snippets.

@fujiwara
Last active May 14, 2021 18:05
Show Gist options
  • Save fujiwara/c33927f5b03007c0fdeedd171488e5e5 to your computer and use it in GitHub Desktop.
Save fujiwara/c33927f5b03007c0fdeedd171488e5e5 to your computer and use it in GitHub Desktop.
ecspresso handbook diff between v1.3 and v1.5.4
diff --git a/books/ecspresso-handbook/codedeploy.md b/books/ecspresso-handbook/codedeploy.md
index 7204de5..e68c4ea 100644
--- a/books/ecspresso-handbook/codedeploy.md
+++ b/books/ecspresso-handbook/codedeploy.md
@@ -185,9 +185,9 @@ https://docs.aws.amazon.com/ja_jp/AmazonECS/latest/userguide/deployment-type-blu
Blue/Green デプロイを設定したサービスは、オートスケーリングが有効な状態ではデプロイが行えません。
-`ecspresso deploy --suspend-autoscaling` を指定することで、デプロイ前に Application Autoscaling を一時的に停止できます。
+`ecspresso deploy --suspend-auto-scaling` を指定することで、デプロイ前に Application Autoscaling を一時的に停止できます。
-ただし、v1.2.1 の時点では ecspresso ではオートスケーリングの再開(resume)を行えません。
+デプロイが完了後にオートスケールを有効化するために、`ecspresso scale --resume-auto-scaling` を実行できます。
## deploy のオプション `--rollback-events`
@@ -204,7 +204,10 @@ CodeDeploy でのデプロイの場合、`ecspresso deploy` は CodeDeploy で
## CodeDeploy を利用したサービスのロールバック
-サービスが CodeDeploy を利用している場合、`ecspresso rollback` によるロールバックは行えません。ロールバックは CodeDeploy の機能を使用して行ってください。
+サービスが CodeDeploy を利用している場合、`ecspresso rollback` によるロールバックを実行すると、次のような挙動を行います。
+
+- CodeDeploy でのデプロイが進行中の場合: 進行中のデプロイを中止する
+- CodeDeploy でのデプロイが完了している場合: ローリングデプロイ同様、現在サービスに指定されているタスク定義のひとつ前のリビジョンを使用して、新しく CodeDeploy でのデプロイを開始する
## フックの追加
diff --git a/books/ecspresso-handbook/config.yaml b/books/ecspresso-handbook/config.yaml
index 090548b..e1df006 100644
--- a/books/ecspresso-handbook/config.yaml
+++ b/books/ecspresso-handbook/config.yaml
@@ -3,9 +3,13 @@ summary: |
Amazon ECS デプロイツール ecspresso の作者による解説本です。
チュートリアル、基本的な使いかた、応用的な使いかた、設計思想と実装、全コマンドのリファレンスを掲載しています。
- ecspresso advent calendar 2020 に掲載した内容を再編集したものです。
+ ecspresso advent calendar 2020 に掲載した内容を再編集、2021年以降にリリースされたv1.3以降の機能追加への記述を追加したものです。
https://adventar.org/calendars/5916
- 章立ては異なりますが、内容自体はほぼ同一です。あらかじめご理解の上購入をお願いします。
+
+ [2021-05-15] v1.5.4 に対応して改訂を行いました。
+ - ECS Exec の章を追加しました
+ - コマンドリファレンスに `tasks` `exec` コマンドを追加しました
+ - ほか、1.4.x, 1.5.x の新機能や修正に対応した改訂を行いました
[2021-01-18] v1.3.0 に対応して改訂を行いました。
- CloudFormation 連携、バージョン固定の章を追加しました
@@ -37,6 +41,7 @@ chapters:
# register
# create
# delete
+ - exec
- template-tips
- codedeploy
- terraform
diff --git a/books/ecspresso-handbook/exec.md b/books/ecspresso-handbook/exec.md
new file mode 100644
index 0000000..e6c3286
--- /dev/null
+++ b/books/ecspresso-handbook/exec.md
@@ -0,0 +1,92 @@
+---
+title: "ECS Exec"
+---
+
+あたかもホスト上で `docker exec` するかのように、ECS タスク (Fargateを含む) に対して起動しているコンテナに入ってコマンドを実行できる ECS Exec 機能が2021年3月にリリースされています。
+
+https://aws.amazon.com/jp/blogs/news/new-using-amazon-ecs-exec-access-your-containers-fargate-ec2/
+
+ecspresso v1.5 では exec コマンドが追加がされ、ECS Exec が実行できます。
+
+利用するためには、事前に [Session Manager plugin](https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html) のインストールが必要です。
+
+## ECS Exec を有効にする
+
+サービス定義の `enableExecuteCommand` 属性を true に設定して、ecspresso create または deploy を実行します。起動中の ECS サービスに対してもあとから変更可能です。
+
+```json
+{
+ // ...
+ "enableExecuteCommand": true
+}
+```
+
+ECS Exec に必要な権限などが揃っているかどうかは [amazon-ecs-exec-checker](https://github.com/aws-containers/amazon-ecs-exec-checker) で確認すると便利です。
+
+https://github.com/aws-containers/amazon-ecs-exec-checker
+
+
+## ECS Exec を実行する
+
+有効化後は、ecspresso exec コマンドを使用して、起動中のタスクに対してコマンドを実行できます。
+
+```
+$ ecspresso --config config.yaml exec
+```
+
+ecspresso exec コマンドを実行すると、実行中のサービスと同じタスク定義を使用しているタスクが一覧で表示され、そのうちの1タスクを選択するプロンプトが表示されます。
+
+```
+$ ecspresso --config config.yaml --envfile envfile exec
+16f713c99d134bd081dc9889dd1a6379 ecspresso-test:287 PENDING RUNNING 2021-05-15T02:04:04+09:00 service:nginx-local FARGATE
+f1371f227c6948fbac194f6ee4aacc44 ecspresso-test:287 RUNNING RUNNING 2021-05-12T17:17:34+09:00 service:nginx-local FARGATE
+fdba8ff985614c79a92c7a5993ae5ba1 ecspresso-test:287 PENDING RUNNING 2021-05-15T02:04:04+09:00 service:nginx-local FARGATE
+Enter task ID:
+```
+
+タスクのIDを入力すると、タスクに複数コンテナがある場合はタスク内のどのコンテナに対して Exec するかのプロンプトが表示されます。(タスクに1コンテナしかない場合は表示されずにExecの実行に進みます)
+
+```
+Enter task ID: 16f713c99d134bd081dc9889dd1a6379
+task ID=16f713c99d134bd081dc9889dd1a6379
+bash
+nginx
+Enter container name:
+```
+
+コンテナ名を入力すると、ECS Exec によってコマンド(無指定の場合は `sh`)が対話モードで実行されます。
+
+```
+Enter container name: bash
+container name=bash
+
+Starting session with SessionId: ecs-eni-provisioning-0deba3087b65bd2b5
+#
+```
+
+タスクID、コンテナ名、コマンド名を引数で明示的に指定して、Execを実行することもできます。
+
+```
+$ ecspresso --config config.yaml exec --id 09fe1ac8f4a843dea1cc4dca0efdb6dc --container bash --command "uname -a"
+
+Starting session with SessionId: ecs-execute-command-02f499561ddff5056
+Linux 09fe1ac8f4a843dea1cc4dca0efdb6dc-987533343 4.14.225-168.357.amzn2.x86_64 #1 SMP Mon Mar 15 18:00:02 UTC 2021 x86_64 GNU/Linux
+
+
+Exiting session with sessionId: ecs-execute-command-02f499561ddff5056.
+```
+
+## 選択インターフェース
+
+ecspresso exec では複数のタスクやコンテナから実際にコマンドを実行する対象を選択する場面があります。
+デフォルトでは ID やコンテナ名の入力を求めるプロンプトが提示されますが、[peco](https://github.com/peco/peco) や [fzf](https://github.com/junegunn/fzf) に代表される、複数行の入力からインタラクティブに1行を選択するコマンドを使うことができます。
+
+ecspresso の設定ファイルに `filter_comand` でコマンドを指定してください。
+
+```yaml
+filter_command: peco
+```
+
+IDやコンテナ名をプロンプトから入力する代わりに、指定したコマンドによる任意の選択インターフェースが利用できます。
+
+https://asciinema.org/a/405167
diff --git a/books/ecspresso-handbook/install.md b/books/ecspresso-handbook/install.md
index 02b4dde..3fb8a1e 100644
--- a/books/ecspresso-handbook/install.md
+++ b/books/ecspresso-handbook/install.md
@@ -9,13 +9,13 @@ ecspresso は Go 言語で実装された CLI ツールです。依存のない
[GitHubのリリース](https://github.com/kayac/ecspresso/releases)からインストールする環境に応じたファイルを取得、展開して、適切なpathに配置してください。
```console
-$ curl -sL -o ecspresso-v1.2.1-linux-amd64.zip https://github.com/kayac/ecspresso/releases/download/v1.2.1/ecspresso-v1.2.1-linux-amd64.zip
-$ unzip ecspresso-v1.2.1-linux-amd64.zip
-Archive: ecspresso-v1.2.1-linux-amd64.zip
- inflating: ecspresso-v1.2.1-linux-amd64
-$ sudo install ecspresso-v1.2.1-linux-amd64 /usr/local/bin/ecspresso
+$ curl -sL -o ecspresso-v1.5.4-linux-amd64.zip https://github.com/kayac/ecspresso/releases/download/v1.5.4/ecspresso-v1.5.4-linux-amd64.zip
+$ unzip ecspresso-v1.5.4-linux-amd64.zip
+Archive: ecspresso-v1.5.4-linux-amd64.zip
+ inflating: ecspresso-v1.5.4-linux-amd64
+$ sudo install ecspresso-v1.5.4-linux-amd64 /usr/local/bin/ecspresso
$ ecspresso version
-ecspresso v1.2.1
+ecspresso v1.5.4
```
# Homebrew を使う
@@ -25,7 +25,7 @@ ecspresso v1.2.1
```console
$ brew install kayac/tap/ecspresso
$ brew list ecspresso
-/home/linuxbrew/.linuxbrew/Cellar/ecspresso/1.2.1/bin/ecspresso
+/home/linuxbrew/.linuxbrew/Cellar/ecspresso/1.5.4/bin/ecspresso
```
# CI/CD 環境で使う
@@ -43,7 +43,7 @@ https://circleci.com/orbs/registry/orb/fujiwara/ecspresso
# .circleci/config.yml
version: 2.1
orbs:
- ecspresso: fujiwara/ecspresso@0.0.12
+ ecspresso: fujiwara/ecspresso@0.0.14
jobs:
install:
docker:
@@ -51,7 +51,7 @@ jobs:
steps:
- checkout
- ecspresso/install:
- version: v1.2.0
+ version: v1.5.4 # or latest
- run:
command: |
ecspresso version
@@ -59,9 +59,11 @@ jobs:
![](https://storage.googleapis.com/zenn-user-upload/rriaoh1dshu2n1gqegasds3dzw6k)
+`version` に `latest` を指定すると、実行時点の最新版をインストールします。
+
## GitHub Actions
-`kayac/ecspresso@v0` を use します。
+`kayac/ecspresso@v1` を use します。
```yaml
jobs:
@@ -69,11 +71,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- - uses: kayac/ecspresso@v0
+ - uses: kayac/ecspresso@v1
with:
- version: v1.2.0
+ version: v1.5.4 # or latest
- run: |
ecspresso version
```
![](https://storage.googleapis.com/zenn-user-upload/pnagnrbcryz9bhuk5ljc7q6mo1ep)
+
+`version` に `latest` を指定すると、実行時点の最新版をインストールします。
diff --git a/books/ecspresso-handbook/intro.md b/books/ecspresso-handbook/intro.md
index d0ad7e6..4437c20 100644
--- a/books/ecspresso-handbook/intro.md
+++ b/books/ecspresso-handbook/intro.md
@@ -5,9 +5,9 @@ free: true
# はじめに
-この本は、[ecspresso advent calendar 2020](https://adventar.org/calendars/5916) を元に再編集したものです。
+この本は、[ecspresso advent calendar 2020](https://adventar.org/calendars/5916) を再編集し、2021年以降にリリースされたv1.3以降の機能追加への記述を追加したものです。
-2021年1月にリリースされた v1.3.0 に対応しています。新バージョンのリリースに伴って、内容が更新される可能性があります。
+2021年5月にリリースされた v1.5.4 に対応しています。新バージョンのリリースに伴って、内容が更新される可能性があります。
# ecspresso とは
diff --git a/books/ecspresso-handbook/oss.md b/books/ecspresso-handbook/oss.md
index f82f46e..fe23f67 100644
--- a/books/ecspresso-handbook/oss.md
+++ b/books/ecspresso-handbook/oss.md
@@ -10,24 +10,26 @@ https://golang.org/
## go.mod
-v1.3.0 の時点の依存が記述されている `go.mod` ファイルは次のようになっています。
+v1.5.4 の時点の依存が記述されている `go.mod` ファイルは次のようになっています。
```
require (
- github.com/Songmu/prompter v0.4.0
+ github.com/Songmu/prompter v0.5.0
github.com/alecthomas/kingpin v1.3.8-0.20190930021037-0a108b7f5563
- github.com/aws/aws-sdk-go v1.36.15
- github.com/fatih/color v1.9.0
+ github.com/aws/aws-sdk-go v1.38.30
+ github.com/fatih/color v1.10.0
github.com/fujiwara/cfn-lookup v0.0.2
- github.com/fujiwara/tfstate-lookup v0.1.1
- github.com/google/go-cmp v0.5.2
- github.com/hashicorp/go-version v1.2.1
- github.com/kayac/go-config v0.5.0
+ github.com/fujiwara/tfstate-lookup v0.2.2
+ github.com/google/go-cmp v0.5.5
+ github.com/hashicorp/go-envparse v0.0.0-20200406174449-d9cfd743a15e
+ github.com/hashicorp/go-version v1.3.0
+ github.com/kayac/go-config v0.5.1
github.com/kylelemons/godebug v1.1.0
github.com/mattn/go-isatty v0.0.12
github.com/morikuni/aec v1.0.0
+ github.com/olekukonko/tablewriter v0.0.5
github.com/pkg/errors v0.9.1
- gopkg.in/yaml.v2 v2.3.0
+ gopkg.in/yaml.v2 v2.4.0
)
```
@@ -82,13 +84,19 @@ https://github.com/google/go-cmp
複雑な構造を持った値を簡単に比較するためのライブラリです。テストで使用しています。
+## github.com/hashicorp/go-envparse
+
+共通オプションの `--envfile` で指定した環境変数定義ファイルの解析に使用しています。
+
+[HashiCorp](https://www.hashicorp.com/) の Go のライブラリは非常に渋くて実用的なものが多いですね。実用的なツールを実装するための小さくてよいパーツがたくさんあります。
+
## github.com/hashicorp/go-version
https://github.com/hashicorp/go-version
SemVer のバージョン番号処理を行うライブラリです。設定ファイルの `required_version` を実装するために使用しています。
-[HashiCorp](https://www.hashicorp.com/) の Go のライブラリは非常に渋くて実用的なものが多いですね。実用的なツールを実装するための小さくてよいパーツがたくさんあります。
+`go-envparse` 同様、HashiCorp の渋くて便利なライブラリです。
## github.com/kayac/go-config
@@ -116,6 +124,14 @@ https://github.com/morikuni/aec
`deploy` コマンドなどで、定期的に更新されていくイベントログを端末上の同一行で表示するために使用しています。
+## github.com/olekukonko/tablewriter
+
+https://github.com/olekukonko/tablewriter
+
+ASCII table を表示するためのライブラリです。
+
+`tasks` コマンドでタスク一覧を表形式で出力するために使用しています。
+
## github.com/pkg/errors
https://github.com/pkg/errors
diff --git a/books/ecspresso-handbook/reference.md b/books/ecspresso-handbook/reference.md
index 368a3be..c2f4aa2 100644
--- a/books/ecspresso-handbook/reference.md
+++ b/books/ecspresso-handbook/reference.md
@@ -8,10 +8,12 @@ ecspresso のコマンドリファレンスです。
usage: ecspresso [<flags>] <command> [<args> ...]
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --color enalble colored output
+ --help Show context-sensitive help (also try --help-long and
+ --help-man).
+ --config=CONFIG config file
+ --debug enable debug log
+ --envfile=ENVFILE ... environment files
+ --color enable colored output
Commands:
help [<command>...]
@@ -23,11 +25,13 @@ Commands:
deploy [<flags>]
deploy service
- scale --tasks=TASKS [<flags>]
- scale service. equivalent to deploy --skip-task-definition --no-update-service
+ scale [<flags>]
+ scale service. equivalent to deploy --skip-task-definition
+ --no-update-service
refresh [<flags>]
- refresh service. equivalent to deploy --skip-task-definition --force-new-deployment --no-update-service
+ refresh service. equivalent to deploy --skip-task-definition
+ --force-new-deployment --no-update-service
create [<flags>]
create service
@@ -49,6 +53,54 @@ Commands:
wait
wait until service stable
+
+ init --service=SERVICE [<flags>]
+ create service/task definition files by existing ECS service
+
+ diff
+ display diff for task definition compared with latest one on ECS
+
+ appspec [<flags>]
+ output AppSpec YAML for CodeDeploy to STDOUT
+
+ verify [<flags>]
+ verify resources in configurations
+
+ render [<flags>]
+ render config, service definition or task definition file to stdout
+
+ tasks [<flags>]
+ list tasks that are in a service or having the same family
+
+ exec [<flags>]
+ execute command in a task
+```
+
+# 各サブコマンド共通のオプション
+
+## `--config=CONFIG`
+
+ecspresso の設定ファイルを指定します。
+
+## `--debug`
+
+デバッグログ出力を有効にします。
+
+## `--envfile=ENVFILE`
+
+ecspresso 実行時に設定する環境変数をファイルで指定します。
+
+ファイルの形式は一般的な envfile 形式で、`export` は記述されていてもいなくても同様に動作します。
+
+```sh
+export FOO=foo
+BAR=bar
+```
+
+オプションは複数回指定可能です。複数回指定した場合には、後に指定されたファイルの内容で上書きされます。
+
+```
+$ ecspresso --envfile base.env --envfile override.env ...
```
# version
@@ -57,7 +109,7 @@ ecspresso のバージョンを標準出力へ出力します。
```
$ ecspresso version
-ecspresso v1.2.1
+ecspresso v1.5.4
```
# deploy
@@ -72,23 +124,21 @@ usage: ecspresso deploy [<flags>]
deploy service
Flags:
- --help Show context-sensitive help (also try --help-long and
- --help-man).
- --config=CONFIG config file
- --debug enable debug log
+ --resume-auto-scaling resume application auto-scaling attached with the ECS service
--dry-run dry-run
--tasks=-1 desired count of tasks
--skip-task-definition skip register a new task definition
--force-new-deployment force a new deployment of the service
- --no-wait exit ecspresso immediately after just deployed without
- waiting for service stable
- --suspend-auto-scaling set suspend to auto-scaling attached with the ECS service
+ --no-wait exit ecspresso immediately after just deployed without waiting for
+ service stable
+ --suspend-auto-scaling suspend application auto-scaling attached with the ECS service
--rollback-events=ROLLBACK-EVENTS
rollback when specified events happened
(DEPLOYMENT_FAILURE,DEPLOYMENT_STOP_ON_ALARM,DEPLOYMENT_STOP_ON_REQUEST,...)
CodeDeploy only.
--update-service update service attributes by service definition
- --latest-task-definition deploy with latest task definition without registering new task definition
+ --latest-task-definition deploy with latest task definition without registering new task
+ definition
```
### `--tasks`
@@ -122,7 +172,11 @@ CI/CD環境で実行する場合など、デプロイ(=タスクの入れ換え)
### `--suspend-auto-scaling`
-デプロイ前に、一時的にオートスケール (Application Auto Scaling)の動作を抑止(suspend)します。デプロイが完了すると suspend は解除されます。
+デプロイ前に、オートスケール (Application Auto Scaling)の動作を抑止(suspend)します。
+
+### `--resume-auto-scaling`
+
+デプロイ前に、抑止(suspend)されていたオートスケール (Application Auto Scaling)の動作を再開します。
### `--rollback-events`
@@ -149,10 +203,6 @@ usage: ecspresso rollback [<flags>]
rollback service
Flags:
- --help Show context-sensitive help (also try --help-long and
- --help-man).
- --config=CONFIG config file
- --debug enable debug log
--dry-run dry-run
--deregister-task-definition deregister rolled back task definition
--no-wait exit ecspresso immediately after just rollbacked without
@@ -178,10 +228,6 @@ usage: ecspresso rollback [<flags>]
rollback service
Flags:
- --help Show context-sensitive help (also try --help-long and
- --help-man).
- --config=CONFIG config file
- --debug enable debug log
--dry-run dry-run
--deregister-task-definition deregister rolled back task definition
--no-wait exit ecspresso immediately after just rollbacked without
@@ -210,9 +256,6 @@ usage: ecspresso status [<flags>]
show status of service
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
--events=2 show events num
```
@@ -233,11 +276,6 @@ usage: ecspresso deploy [<flags>]
deploy service
Flags:
- --help Show context-sensitive help (also try --help-long and
- --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --dry-run dry-run
--tasks=-1 desired count of tasks
--skip-task-definition skip register a new task definition
--force-new-deployment force a new deployment of the service
@@ -306,29 +344,37 @@ ECS サービスで動作しているタスク数を変更します。(v1.3.0以
## scale コマンドのオプション
```
-usage: ecspresso scale --tasks=TASKS [<flags>]
+usage: ecspresso scale [<flags>]
scale service. equivalent to deploy --skip-task-definition --no-update-service
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --color enalble colored output
- --dry-run dry-run
- --tasks=TASKS desired count of tasks
- --no-wait exit ecspresso immediately after just deployed without waiting for service
- stable
+ --resume-auto-scaling resume application auto-scaling attached with the ECS
+ service
+ --dry-run dry-run
+ --tasks=-1 desired count of tasks
+ --suspend-auto-scaling suspend application auto-scaling attached with the ECS
+ service
+ --no-wait exit ecspresso immediately after just deployed without
+ waiting for service stable
```
### `--tasks`
-ECS サービスにあらたに設定するタスク数を数値で指定します。必須です。
+ECS サービスに設定するタスク数を数値で指定します。指定しない場合は現在のタスク数を維持します。
### `--no-wait`
`deploy --no-wait` と同様、タスクの入れ替えを指示した後に完了を待たず、即終了します。
+### `--suspend-auto-scaling`
+
+オートスケール (Application Auto Scaling)の動作を抑止(suspend)します。
+
+### `--resume-auto-scaling`
+
+抑止(suspend)されていたオートスケール (Application Auto Scaling)の動作を再開します。
+
# refresh
ECS サービスで動作しているタスクを、新しく起動したタスクに全て入れ換えます。
@@ -341,9 +387,6 @@ usage: ecspresso refresh [<flags>]
refresh service. equivalent to deploy --skip-task-definition --force-new-deployment --no-update-service
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
--dry-run dry-run
--no-wait exit ecspresso immediately after just deployed without waiting for service stable
```
@@ -365,9 +408,6 @@ usage: ecspresso wait
wait until service stable
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
```
`wait` コマンドには固有のオプションはありません。
@@ -384,9 +424,6 @@ usage: ecspresso diff
display diff for task definition compared with latest one on ECS
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
--color enalble colored output
```
@@ -406,11 +443,9 @@ usage: ecspresso verify [<flags>]
verify resources in configurations
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --color enalble colored output
- --put-logs put verification logs to CloudWatch Logs
+ --color enable colored output
+ --get-secrets get secrets from ParameterStore or SecretsManager
+ --put-logs put verification logs to CloudWatch Logs
```
### `--put-logs`
@@ -423,6 +458,12 @@ Flags:
出力結果を色つきにします。端末で実行されている場合にはデフォルトで有効、端末以外で実行されている場合にはデフォルトで無効 (`--no-color`) になります。
+### `--get-secrets`
+
+コンテナ定義の secrets で指定しているシークレットを実際に SSM パラメータストアや Secrets Manager から取得できるかどうかを検証します。(デフォルトで有効です)
+
+`verify` コマンドを実行する環境にシークレットを取得する権限を与えたくない場合には、`--no-get-secrets` を指定することで、シークレットの検証を省略できます。
+
# render
設定ファイルと定義ファイルをレンダリングし、標準出力に出力します。
@@ -435,10 +476,6 @@ usage: ecspresso render [<flags>]
render config, service definition or task definition file to stdout
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --color enable colored output
--service-definition render service definition
--task-definition render task definition
--config-file render config file
@@ -468,11 +505,6 @@ usage: ecspresso run [<flags>]
run task
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --envfile=ENVFILE ... environment files
- --color enable colored output
--dry-run dry-run
--task-def=TASK-DEF task definition json for run task
--no-wait exit ecspresso after task run
@@ -564,10 +596,6 @@ usage: ecspresso register [<flags>]
register task definition
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --color enalble colored output
--dry-run dry-run
--output output registered task definition
```
@@ -588,11 +616,6 @@ usage: ecspresso create [<flags>]
create service
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --color enalble colored output
- --dry-run dry-run
--tasks=-1 desired count of tasks
--no-wait exit ecspresso immediately after just created without waiting for service stable
```
@@ -623,10 +646,6 @@ usage: ecspresso delete [<flags>]
delete service
Flags:
- --help Show context-sensitive help (also try --help-long and --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --color enalble colored output
--dry-run dry-run
--force force delete. not confirm
```
@@ -648,11 +667,6 @@ usage: ecspresso appspec [<flags>]
output AppSpec YAML for CodeDeploy to STDOUT
Flags:
- --help Show context-sensitive help (also try --help-long and
- --help-man).
- --config=CONFIG config file
- --debug enable debug log
- --color enalble colored output
--task-definition="latest" use task definition arn in AppSpec (latest, current or Arn)
```
@@ -664,3 +678,79 @@ AppSpec ファイルに出力する `TaskDefinition:` を指定します。デ
- `current`: 現在 ECS サービスが使用しているタスク定義
- タスク定義の Arn: 直接 ARN を指定できます
`arn:aws:ecs:{AWS_REGION}:{ACCOUNT_ID}:task-definition/{TASK_DEFINITION_NAME}:{REVISION}`
+
+# tasks
+
+ecspresso が管理しているタスク定義を利用している全てのタスクの情報を取得します。
+
+対象は以下のタスクです。
+
+- ECSサービスから起動されているタスク
+- ECSサービスで使用しているタスク定義を利用している、ECSサービス管理外のタスク (ecspresso run で実行されているタスク)
+
+## `tasks` コマンドのオプション
+
+```
+usage: ecspresso tasks [<flags>]
+
+list tasks that are in a service or having the same family
+
+Flags:
+ --id="" task ID
+ --output=table output format (table|json|tsv)
+ --find find a task from tasks list and dump it as JSON
+ --stop stop a task
+ --force stop a task without confirmation prompt
+```
+
+### `--id`
+
+exec 対象のタスクIDを指定します。
+
+### `--output=(table|json|tsv)`
+
+出力形式を指定します。
+
+### `--find`
+
+対象タスクが複数ある場合に、その1タスクを選択して詳細情報を JSON 形式で出力します。
+
+### `--stop`
+
+選択したタスクを停止します。
+
+### `--force`
+
+`--stop` オプションでタスクを停止する場合に、確認ダイアログを表示せずに停止を実行します。
+
+
+# exec
+
+ECS Exec を使用して、タスクのコンテナ上でコマンドを実行します。
+
+実行するためには、[session-manager-plugin](https://docs.aws.amazon.com/ja_jp/systems-manager/latest/userguide/session-manager-working-with-install-plugin.html) がインストールされている必要があります。
+
+## `exec` コマンドのオプション
+
+```
+usage: ecspresso exec [<flags>]
+
+execute command in a task
+
+Flags:
+ --id="" task ID
+ --command="sh" command
+ --container=CONTAINER container name
+```
+
+### `--id`
+
+exec 対象のタスクIDを指定します。指定がない場合はタスクIDを入力するのプロンプト (設定ファイルで `filter_command` が定義されている場合はそのコマンドでの選択動作) が表示されます。
+
+### `--container`
+
+exec 対象のタスク内のコンテナ名を指定します。指定がない場合はコンテナ名を入力するのプロンプト (設定ファイルで `filter_command` が定義されている場合はそのコマンドでの選択動作) が表示されます。
+
+### `--command`
+
+exec するコマンドを指定します。デフォルトは `sh` です。
diff --git a/books/ecspresso-handbook/terraform.md b/books/ecspresso-handbook/terraform.md
index f25c046..5fe68ef 100644
--- a/books/ecspresso-handbook/terraform.md
+++ b/books/ecspresso-handbook/terraform.md
@@ -50,7 +50,7 @@ plugins:
path: terraform.tfstate
```
-ecspresso v1.3.0 以降では S3, HTTP(S) の URL を指定して、リモートのステートを直接読み込めます。
+ecspresso v1.3.0 以降では S3, HTTP(S) の URL を指定して、リモートのステートを直接読み込めます。v1.5.2 以降では、GCS (Google Cloud Storage) の URL (gs://) にも対応しています。
```yaml
plugins:
@@ -164,6 +164,16 @@ Terraform のリソースを `for_each` などで記述すると、リソース
"{{ tfstate `aws_subnet.az['a'].id` }}"
```
+### テンプレート関数 `tfstatef`
+
+`resource.name["foo"].id` のような、リソース名中に可変要素が入る参照を行う場合に便利な関数が定義されています。
+
+環境変数 `AZ` を使用して aws_subnet.az['$AZ'].id というリソース名を tfstate から参照したい場合には、次のように記述できます。
+
+```
+{{ tfstatef `aws_subnet.az['%s'].id` (must_env `AZ`) }}
+```
+
### tfstate を実際に参照してどんな値が入ってるか確認したい
tfstate は JSON 形式なので、人間が直接読むことはできます。ただし、Terraform でリソースを指定するアドレスを文字列で検索してリソースにたどりつくことはできないため、確認に便利な方法を2点紹介します。
diff --git a/books/ecspresso-handbook/usecases.md b/books/ecspresso-handbook/usecases.md
index 3e18329..eb97055 100644
--- a/books/ecspresso-handbook/usecases.md
+++ b/books/ecspresso-handbook/usecases.md
@@ -32,7 +32,7 @@ status コマンドのオプションについては [コマンドリファレ
# ECS サービスのタスク数を変更する
-`ecspresso scale` コマンド (v1.3.0以降) は、ECS サービスのタスク数を変更します。
+`ecspresso scale` コマンドは、ECS サービスのタスク数を変更します。
```
$ ecspresso scale --config config.yaml scale --tasks 2
@@ -257,13 +257,13 @@ ECSのタスクは、それ単体では動作しません。タスクが動作
これらの各種リソースが存在していなかったりアクセス権がなかったりすると、タスクは実行できません。タスク定義の登録時にはこれらの外部リソースはチェックされないため、不備は実際に実行してみないと気がつけないことが多くあります。
-実行前に各種リソースが利用可能かを検証できれば、タスクを起動してみて失敗する可能性を減らせます。ecspresso v1.2 ではそのために `verify` コマンドをサポートしました。
+実行前に各種リソースが利用可能かを検証できれば、タスクを起動してみて失敗する可能性を減らせます。ecspresso は そのために `verify` コマンドを用意しています。
## サービス/タスク定義が依存するAWS上の各種リソースが利用可能か検証する `verify` コマンド
`ecspresso verify` コマンドは、サービス/タスク定義を解析し、依存リソースが存在しているか、実際にアクセスできるかを検証します。
-v1.3.0 の時点では、以下の項目を検証しています。
+v1.5 の時点では、以下の項目を検証しています。
- タスクロール、タスク実行ロールが存在し、`ecs-tasks.amazonaws.com` によって引き受け(Assume Role)可能である
- タスク定義のネットワークモードが `awsvpc` の場合、サービス定義に `networkConfiguration.awsvpcConfiguration` 要素が定義されている
@@ -315,7 +315,7 @@ assume role ができなかった場合でも、現在の権限で検証を続
```
$ ecspresso --config config.yaml verify --no-put-logs
-WARNING: failed to assume role to taskExecutuionRole. Continue to verifiy with current session.
+INFO: failed to assume role to taskExecutuionRole. Continue to verifiy with current session.
AccessDenied: User: arn:aws:iam::123456789012:user/xxxx is not authorized to perform:
sts:AssumeRole on resource: arn:aws:iam::123456789012:role/ecsTaskExecutionRole
status code: 403, request id: 99015bdb-5a6f-4be7-80d7-42874a74ec7c
@@ -341,12 +341,6 @@ sts:AssumeRole on resource: arn:aws:iam::123456789012:role/ecsTaskExecutionRole
2020/12/11 16:40:39 nginx-service/ecspresso-demo Verify OK!
```
-## 注意点
-
-IAMのマネージドポリシーである AmazonECSTaskExecutionRolePolicy には、ロードバランサーへの読み取り権が附与されていません。タスク実行ロールにはロードバランサーの読み取り権限は不要ですが、ecspresso verify でターゲットグループの確認をするためには必要です。
-
-ターゲットグループの検証が `elasticloadbalancing:DescribeTargetGroups` 権限がないという理由で失敗する場合には、タスク実行ロールに `elasticloadbalancing:DescribeTargetGroups` もしくはマネージドポリシーの ElasticLoadBalancingReadOnly を附与してください。
-
`verify` コマンドのオプションについては [コマンドリファレンス](reference#verify) を参照してください。
# 設定ファイルと定義ファイルをレンダリングする
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment