再起動がともなうAmazon EC2のスケジュールイベントの開始時間を変更出来る機能がリリースされました。

2019.04.02

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

こんにちは 園部です。

EC2 を利用していると AWSからイベント通知が届き、指定された期間でメンテナンスが実行されたことはないでしょうか?

このイベントに対応されている担当者の皆様に

少し嬉しいサービスがリリースされましたので、共有させていただきます。

Amazon EC2 でスケジュールされたイベントの時間を選択できる新機能のご紹介

注:実際のスケジュールイベントを都合よく準備出来なかったため、机上での紹介となります。

前置き

冒頭にも書きましたが AWS では、セキュリティパッチ適用などの理由によりホストやネットワーク機器へのメンテナンスが実施されます。

(EC2 のみではなく RDS, ElastiCache, DirectConnect なども同様に実施されています)

今回は EC2を取り上げていきます。 EC2で、スケジュールイベントに関する情報は以下にまとめられています。 EC2を導入される際は、一度ご確認されることをお勧めします。

インスタンスの予定されたイベント(公式ドキュメント)

このイベント自体は、インフラストラクチャを健全に保つために必要なもので、回避自体よりも停止や再起動に備えた設計を行うことが最適とされています。

とはいえ、、こういうシーンもあるのではないでしょうか。(私はありました。)

「AWSからイベント通知来たよ!!」

「えー。この日時は勘弁して欲しい。」

「もうメンテナンス実行される前に、やっちゃおうよ。(夜中)」

そんな声を聞いてかどうかはわかりませんが、再起動をともなうスケジュールイベントの開始時間を変更する機能がリリースされました。

それでは見ていきましょう。

※ 現時点では利用するにはいくつかの条件があります。そちらについては、この後に記載していきます。

スケジュールされたイベントの時間を選択できる新機能 とは?

※ 現時点では、英語ドキュメント にのみ、記載があります。

You can reschedule most reboot events so that your instance is rebooted at a specific date and time that suits you.

  • スケジュールされた再起動イベントに関して、特定の日時に変更し再起動させることが出来る。

マネジメントコンソールから変更する

マネジメントコンソール へログイン >>> EC2 へ移動 >>> Event へ移動 >>> Filter から Instance resources を選択

対象イベントを選択 >>> Actions >>> Schedule Event を選択

※ 対象イベントがあれば、設定用ウィンドウが表示されます。

前述の通りスケジュールイベントが用意できていませんので、ドキュメントベースの説明となります。

Event start time を入力 >>> Schedule Event を選択

数分程度で、変更が完了します。

CLIから変更する

CLIでは、 modify-instance-event-start-time を利用します。

AWS CLI Command Reference

実行環境

$ aws --version
aws-cli/1.16.125 Python/2.7.10 Darwin/18.5.0 botocore/1.12.115

コマンド内容

$ aws ec2 modify-instance-event-start-time help

NAME
       modify-instance-event-start-time -

DESCRIPTION
       Modifies the start time for a scheduled Amazon EC2 instance event.

       See also: AWS API Documentation

       See 'aws help' for descriptions of global parameters.

SYNOPSIS
            modify-instance-event-start-time
          [--dry-run | --no-dry-run]
          --instance-id 
          --instance-event-id 
          --not-before 
          [--cli-input-json ]
          [--generate-cli-skeleton ]

OPTIONS
       --dry-run | --no-dry-run (boolean)
          Checks  whether  you  have  the required permissions for the action,
          without actually making the request, and provides an error response.
          If  you have the required permissions, the error response is DryRun-
          Operation . Otherwise, it is UnauthorizedOperation.
          
       --instance-id (string)
          The ID of the instance with the scheduled event.

       --instance-event-id (string)
          The ID of the event whose date and time you are modifying.

       --not-before (timestamp)
          The new date and time when the event will take place.

       --cli-input-json (string) Performs service operation based on the  JSON
       string  provided. The JSON string follows the format provided by --gen-
       erate-cli-skeleton. If other arguments  are  provided  on  the  command
       line,  the CLI values will override the JSON-provided values. It is not
       possible to pass arbitrary binary values using a JSON-provided value as
       the string will be taken literally.

       --generate-cli-skeleton  (string)  Prints  a  JSON skeleton to standard
       output without sending an API request. If provided with no value or the
       value input, prints a sample input JSON that can be used as an argument
       for --cli-input-json. If provided with the value output,  it  validates
       the command inputs and returns a sample output JSON for that command.

       See 'aws help' for descriptions of global parameters.

OUTPUT
       Event -> (structure)
          Describes a scheduled event for an instance.

          InstanceEventId -> (string)
              The ID of the event.

          Code -> (string)
              The event code.

          Description -> (string)
              A description of the event.

              After  a scheduled event is completed, it can still be described
              for up to a week. If the event has been completed, this descrip-
              tion starts with the following text: [Completed].

          NotAfter -> (timestamp)
              The latest scheduled end time for the event.

          NotBefore -> (timestamp)
              The earliest scheduled start time for the event.

          NotBeforeDeadline -> (timestamp)
              The deadline for starting the event.

実行例

$ aws ec2 modify-instance-event-start-time --instance-id i-1234567890abcdef0 --instance-event-id instance-event-0d59937288b749b32 --not-before 2019-03-25T10:00:00.000
  • instance-id: 対象インスタンス
  • instance-event-id: 対象イベントID
  • not-before: 変更する開始時間(UTC)

数分程度で、変更が完了します。

変更結果確認

$ aws ec2 describe-instance-status --instance-id i-1234567890abcdef0
[
    "Events": [
                {
                    "InstanceEventId": "instance-event-0d59937288b749b32",
                    "Code": "system-reboot",
                    "Description": "The instance is scheduled for a reboot",
                    "NotAfter": "2019-03-14T22:00:00.000Z",
                    "NotBefore": "2019-03-25T10:00:00.000Z",
                    "NotBeforeDeadline": "2019-04-05T11:00:00.000Z"
                }
              ]
]
### 注意事項

※ 現時点では、4つほど条件があります。

Only reboot events with an event deadline date can be rescheduled. The event can be rescheduled up to the event deadline date. The Event Deadline column in the console and the NotBeforeDeadline field in the AWS CLI indicate if the event has a deadline date.

  • EventDeadline を持つ再起動イベントのみ本機能は有効です。
  • EventDeadline より前の日時で設定が可能です。

Only reboot events that have not yet started can be rescheduled. The Start Time column in the console and the NotBefore field in the AWS CLI indicate the event start time. Reboot events that are scheduled to start in the next 5 minutes cannot be rescheduled.

  • 未実行のイベントのみが対象です。
  • 5分以内に開始が予定されているイベントについては、変更できません。

The new event start time must be at least 60 minutes from the current time.

  • 新しいイベント開始時刻は、現在時刻から60分以上後である必要があります。

If you reschedule multiple events using the console, the event deadline date is determined by the event with earliest event deadline date.

  • コンソールから複数イベントを変更する際に、Event Deadlineが異なる場合は最も早い日時を基準として判断されます。
  • イベントA: Event Deadline が 2019-04-10T10:00:00
  • イベントB: Event Deadline が 2019-04-15T10:00:00
  • この場合に変更を実行する際には、Event Deadlineは 2019-04-10T10:00:00 として変更可否が判断されます。

さいごに

今回の機能で、AWSが実施するメンテナンスイベントへの柔軟性が少し得られたのではないでしょうか。

導入時に、クラウドベンダーによるイベントへのコントロール可否が導入障壁の要因の一つとなるというケースも見聞きした経験があります。

(もちろん、マインドや設計の変更が最適ではありますが...)課題への回答として、今回機能は、説明材料の一つになるのではないでしょうか。