0
0

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 1 year has passed since last update.

Amazon EventBridgeスケジューラで完了したスケジュールを削除する

Last updated at Posted at 2023-10-08

はじめに

少し前のAWS UpdateでAmazon EventBridgeスケジューラのスケジュールをタスク完了時に削除する機能が追加されました。

これにより、スケジュール実行後に以後必要のないスケジュールを自動で削除することができます。

Amazon EventBridgeスケジューラとは

一言で言えば、EventBridgeのスケジュール機能に特化したサービスです。
EventBridgeスケジューラが公開される以前は、定期実行と言えばEventBridge Ruleを利用した作りこみだったと思いますが、Amazon EventBridge スケジューラを利用することでより柔軟な定期実行のルール作りができるようになりました。
公式がEventBridge Ruleとの比較表を出しているので詳しくはそちらをご参照ください。
今後EventBridgeで定期実行の仕組みを作る場合は特別な理由が無い限りAmazon EventBridgeスケジューラが第一候補となると思います。

やってみる

Amazon EventBridgeのコンソールから「スケジュール」を選択し、「スケジュールを作成」を押下する。
image1.png
スケジュールとターゲットの設定を行う。
今回は適当なLambda関数を作成し、Invokeする。
image2.png

最後にStep3の設定で、「スケジュール完了後のアクション」を「DELETE」とする。
この項目を設定することでスケジュール完了後にこのスケジュールが削除される。

image3.png

設定したタイミングになるとLambda関数がInvokeされたのち、スケジュールが削除される。
image4.png

AWS CLIでスケジュールを設定する場合は--action-after-completionオプションを使用して設定する。
--targetのarnにはLambda関数のarnを指定し、RoleArnには対象のLambda関数をInvokeできる権限を持ったRoleを指定する。

aws scheduler create-schedule \
    --name delete-test-schedule \
    --group-name default \
    --schedule-expression "at(YYYY-MM-DDTHH:MM:SS)" \
    --schedule-expression-timezone "Asia/Tokyo" \
    --flexible-time-window '{"Mode":"OFF"}' \
    --target '{"Arn": "arn:aws:lambda:ap-northeast-1:XXXXXXXXXX:function:FUNCTION_NAME",
"RoleArn": "arn:aws:iam::XXXXXXXXXX:role/service-role/Amazon_EventBridge_Scheduler_LAMBDA_1814e"}' \
    --action-after-completion "DELETE"

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?