LoginSignup
1
1

Amazon ECS Fargate の Task retirement wait time を変更する

Posted at

1. はじめに

  • ECS Fargate を使っているシステムがある。
  • Fargateは、コンテナの実行基盤をAWS側で管理してくれるサービスだが、AWS側で基盤のメンテナンスに伴い、ECSタスクの強制的な再起動が行われる。
  • AWSから基盤メンテナンスの通知を受けてから、タスクの強制再起動が行われるまでの猶予時間が設定可能であるため、システムの運用に合わせた適切な値に変更する。

2. 構成図

image.png

3. 経緯

  • 以前(2023/6/7)に以下のような通知を受領しており、時々AWS側のメンテナンス起因で、タスクの強制再起動が発生する場合があることは認識していた。この時は通知受領から14日後からタスク強制再起動開始、との内容となっていた。

★2023/6/7 のAWSからの通知(抜粋)
CVE パッチまたはその他の重要なパッチを含むソフトウェアアップデートが Fargate にデプロイされました。お客様で必要な操作はありません。新しく起動されるすべてのタスクは、自動的に最新のソフトウェアバージョンを使用します。既存のタスクの場合、これらの更新を適用するにはタスクを再起動する必要があります。次の ECS サービスの一部として実行されているタスクは、2023 年 6 月 19 日 09:00:00 JST から自動的に更新されます。2023 年 6 月 19 日 09:00:00 JST 以降、ECS スケジューラーは、サービスのデプロイ設定を尊重しながら、これらのタスクを徐々に置き換えます。

  • 2023/9/9 に、Fargateの基盤メンテナンス後のタスク強制再起動までの猶予時間について、0/7/14日の3択で選べるようになったとのアップデートがあった。なお、この時点ではデフォルト値が14になっていた。(0にすると、通知と同時にタスク再起動が行われ、14にすると通知後14日経過後にタスク再起動が行われる)

★2023/9/9のAWSからの通知(抜粋)
Starting today, AWS Fargate enables you to configure the task retirement wait period in your ECS Account Settings [1]. The task retirement wait period can be configured to 0, 7 or 14 days. For workloads that require immediate application of the security updates, you should choose the 0 days setting. With 0 days configuration, AWS Fargate applies updates immediately without any delay. With 7 and 14 days configuration, AWS Fargate waits for the requisite time period before the tasks are retired.

  • 2023/11/20に、2023/6/7同様のメンテナンス通知を受領。特に設定変更していなかったため、デフォルト値での動作となり、通知から14日後からタスク強制再起動が行われるようになっていた。

★2023/11/20のAWSからの通知(抜粋)
A software update has been deployed to Fargate which includes security patches and other updates. No action is required on your part. All new tasks launched automatically uses the latest software version. For existing tasks, your tasks need to be restarted in order for these updates to apply. Your tasks running as part of the following ECS Services will be automatically updated beginning Mon, 4 Dec 2023 00:00:00 GMT. After Mon, 4 Dec 2023 00:00:00 GMT, the ECS scheduler will gradually replace these tasks, respecting the deployment settings for your service.

  • 2023/12/5に、AWSから「メンテナンス通知の送付からタスク強制再作成までの猶予期間のデフォルト値を14日から7日間に変更するよ」というサービス仕様変更連絡を受領していた(が見逃していた)。

★2023/12/5のAWSからの通知(抜粋)
These settings provide you more control over how quickly the security updates are applied to your ECS account. We recommend biasing towards a shorter wait period to allow for the patches and updates to be applied sooner. In the last notification, AWS Fargate also shared the intent to change the default wait period from 14 to 7 days starting December 11, 2023. In two weeks, the update to the default wait period will be applied to your AWS account.

  • 2023/12/29に、またメンテナンス通知を受領。上記の仕様変更が行われており、デフォルト値が7に変更されていたため、7日後の1/5(JST)からタスク強制再起動するよという内容になっていた。(えっお正月にやるの?という気持ちになった)

★2023/12/29のAWSからの通知(抜粋)
A software update has been deployed to Fargate which includes includes security patches and other updates. No action is required on your part. All new tasks launched automatically uses the latest software version. For existing tasks, your tasks need to be restarted in order for these updates to apply. Your tasks running as part of the following ECS Services will be automatically updated beginning Thu, 4 Jan 2024 22:55:34 GMT.

  • このシステムにおいては、タスクを自動で再起動されても特に問題はないものの、今回は再起動のタイミングが年始の体制が手薄な時のタイミングになってしまったし、今後は場合によっては先に手動で再起動対応して、不要なアラームの発生を抑止するなどの対応も考えられるため、設定値をデフォルトの7から、最大値の14に変更することとした。そうしておけば、仮に手動でタスク再起動対応するにしても、2週間のリードタイムとなり少し余裕がある。

4. 手順

  • 2024/1時点で、マネコンでの設定変更画面などが用意されていなさそうなため、CLIで設定変更を行う。
(1) 現状の設定値が7であることの確認
user-a:~/environment $ aws ecs list-account-settings --effective-settings
※該当部分のみ
        {
            "name": "fargateTaskRetirementWaitPeriod",
            "value": "7",
            "principalArn": "arn:aws:iam::xxxxxxxxxxxx:user/user-a",
            "type": "user"
        },
 
(2) 設定変更 (7⇒14)
user-a:~/environment $ aws ecs put-account-setting-default --name fargateTaskRetirementWaitPeriod --value 14
{
    "setting": {
        "name": "fargateTaskRetirementWaitPeriod",
        "value": "14",
        "principalArn": "arn:aws:iam::xxxxxxxxxxxx:root",
        "type": "user"
    }
}
(3) 作業後確認(設定が反映されているか)
user-a:~/environment $ aws ecs list-account-settings --effective-settings
※該当部分のみ
        {
            "name": "fargateTaskRetirementWaitPeriod",
            "value": "14",
            "principalArn": "arn:aws:iam::xxxxxxxxxxxx:root",
            "type": "user"
        },
 
(4) 試しに設定可能値(0,7,14)以外を入力してみる⇒予想通りNG
user-a:~/environment $ aws ecs put-account-setting-default --name fargateTaskRetirementWaitPeriod --value 28
 
An error occurred (InvalidParameterException) when calling the PutAccountSettingDefault operation: Invalid setting 'value'

5. 参考サイト

  • 以下の記事に、本件に関する内容が全てきれいにまとめられている。なので改めて記事を書く必要もないかなと思ったが、年末に通知が来て「えっ?」という気持ちになったので、反省として自分でも経緯と対策を一応まとめることにした。

1
1
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
1
1