AWS Lambda の関数状態変化イベントを EventBridge ルールで受け取ってみた

AWS Lambda の関数状態変化イベントを EventBridge ルールで受け取ってみた

Lambda 関数のデプロイや状態の変化を、GetFunction API のポーリングなしで EventBridge のイベントとして拾えるようになりました。関数の作成・更新・公開・削除で実際に届くイベントの種類と中身を確認し、関数 ARN と state で絞り込むルールも試しました。
2026.11.22

はじめに

2026年11月20日に、AWS Lambda 関数の状態変化イベントの Amazon EventBridge サポートが発表されました。

https://aws.amazon.com/about-aws/whats-new/2026/11/aws-lambda-function-state-events/

このアップデートにより、Lambda 関数の作成・更新・公開・削除でバージョンの状態が変わるたびにイベントが EventBridge へ送信されるようになりました。

この記事では、届くイベントの種類と中身、ルールでの絞り込みを試した結果を紹介します。

検証環境

  • リージョン: 東京(ap-northeast-1)
  • AWS CLI: 2.42.1
  • ランタイム: Python 3.13
  • イベントバス: default

全イベントの受信

source だけを条件にしたルールで aws.lambda の全イベントを SQS キューに集め、関数の操作ごとにどのイベントが届くかを確かめました。ルールは全イベント用と絞り込み用の2つで、どちらも先に作ってから関数を操作しました。

キューとルールの作成

SQS キューを作り、EventBridge からの送信を許可するキューポリシーを設定します。

aws sqs create-queue --queue-name fse-verify-all --region ap-northeast-1
aws sqs set-queue-attributes --queue-url https://sqs.ap-northeast-1.amazonaws.com/111122223333/fse-verify-all --attributes file://artifacts/queue-attrs-fse-verify-all.json --region ap-northeast-1
queue-attrs-fse-verify-all.json
{
  "Policy": "{\"Version\": \"2012-10-17\", \"Statement\": [{\"Effect\": \"Allow\", \"Principal\": {\"Service\": \"events.amazonaws.com\"}, \"Action\": \"sqs:SendMessage\", \"Resource\": \"arn:aws:sqs:ap-northeast-1:111122223333:fse-verify-all\", \"Condition\": {\"ArnEquals\": {\"aws:SourceArn\": \"arn:aws:events:ap-northeast-1:111122223333:rule/fse-verify-all\"}}}]}"
}

イベントパターンのファイル pattern-all.json は次の1行です。

{"source": ["aws.lambda"]}

このファイルでルールを作り、キューをターゲットにします。

aws events put-rule --name fse-verify-all --event-pattern file://artifacts/pattern-all.json --region ap-northeast-1
aws events put-targets --rule fse-verify-all --targets 'Id=1,Arn=arn:aws:sqs:ap-northeast-1:111122223333:fse-verify-all' --region ap-northeast-1

操作ごとのイベント

Lambda 関数 fse-verify-target に対して、作成、コード更新、設定更新(メモリを 256 MB へ変更)、バージョン公開、削除を順に実行しました。比較用に、別の関数 fse-verify-other の作成と削除も実行しています。

receive-message で取り出したイベントから、detail-type が AWS API Call via CloudTrail のものを除くと11件でした。

次の表は、この11件を time 順に並べたものです。detail-type は先頭の Event Function Version を省略しています。

time detail-type action state lastUpdateStatus resources(関数名:バージョン)
15:21:48Z Activating CreateFunction Pending - fse-verify-target:$LATEST
15:21:51Z Activated CreateFunction Active Successful fse-verify-target:$LATEST
15:22:01Z Updating UpdateFunctionCode Active InProgress fse-verify-target:$LATEST
15:22:02Z Updated UpdateFunctionCode Active Successful fse-verify-target:$LATEST
15:22:11Z Updating UpdateFunctionConfiguration Active InProgress fse-verify-target:$LATEST
15:22:12Z Updated UpdateFunctionConfiguration Active Successful fse-verify-target:$LATEST
15:22:22Z Activated PublishVersion Active Successful fse-verify-target:1
15:22:31Z Activating CreateFunction Pending - fse-verify-other:$LATEST
15:22:34Z Activated CreateFunction Active Successful fse-verify-other:$LATEST
15:22:44Z Deleted DeleteFunction - - fse-verify-other
15:22:44Z Deleted DeleteFunction - - fse-verify-target

detail の項目

コード更新の Updating イベントを、インデントを整えて示します。

{
  "version": "0",
  "id": "85ce89e9-0a1e-8612-59a9-f97414851cf0",
  "detail-type": "Event Function Version Updating",
  "source": "aws.lambda",
  "account": "111122223333",
  "time": "2026-11-21T15:22:01Z",
  "region": "ap-northeast-1",
  "resources": [
    "arn:aws:lambda:ap-northeast-1:111122223333:function:fse-verify-target:$LATEST"
  ],
  "detail": {
    "revisionId": "049ac8a1-2ed5-4bfe-add0-6be3d4f577ab",
    "lastUpdateStatus": "InProgress",
    "lastUpdateStatusReasonCode": "Creating",
    "action": "UpdateFunctionCode",
    "state": "Active"
  }
}

更新中の state は Active のままなので、更新中か完了かは lastUpdateStatus(InProgress と Successful)で判別します。

この検証で届いたイベントの detail の項目は、detail-type ごとに次のとおりでした。

detail-type detail の項目
Activating action, revisionId, state, stateReason, stateReasonCode
Activated action, lastUpdateStatus, revisionId, state
Updating action, lastUpdateStatus, lastUpdateStatusReasonCode, revisionId, state
Updated action, lastUpdateStatus, revisionId, state
Deleted action, revisionId

イベントの絞り込み

関数 ARN の prefix と state を条件にしたルールで、fse-verify-target のイベントを SQS へ流しました。

イベントパターン

絞り込み用のキュー fse-verify-filtered は、全イベント用と同じ手順で作ります。変えるのは、キュー名と、キューポリシーの Resource のキュー名、aws:SourceArn のルール名です。パターンファイル pattern-filtered.json は次の内容です。

{
  "source": [
    "aws.lambda"
  ],
  "resources": [
    {
      "prefix": "arn:aws:lambda:ap-northeast-1:111122223333:function:fse-verify-target"
    }
  ],
  "detail": {
    "state": [
      "Active"
    ]
  }
}
aws events put-rule --name fse-verify-filtered --event-pattern file://artifacts/pattern-filtered.json --region ap-northeast-1
aws events put-targets --rule fse-verify-filtered --targets 'Id=1,Arn=arn:aws:sqs:ap-northeast-1:111122223333:fse-verify-filtered' --region ap-northeast-1

絞り込みの結果

前述の関数操作で絞り込み用のキューに届いたのは5件でした。次の表は、この5件を time 順に並べたものです。

time detail-type action state lastUpdateStatus resources(関数名:バージョン)
15:22:01Z Updating UpdateFunctionCode Active InProgress fse-verify-target:$LATEST
15:22:02Z Updated UpdateFunctionCode Active Successful fse-verify-target:$LATEST
15:22:11Z Updating UpdateFunctionConfiguration Active InProgress fse-verify-target:$LATEST
15:22:12Z Updated UpdateFunctionConfiguration Active Successful fse-verify-target:$LATEST
15:22:22Z Activated PublishVersion Active Successful fse-verify-target:1

まとめ

AWS Lambda 関数の状態変化イベントの Amazon EventBridge サポートで、関数の作成・更新・公開・削除のイベントが届くことを確認できました。

従来、Lambda の状態変化を追うには、ポーリングや CloudTrail のイベントフィルタリングなどの作り込みが必要でしたが、EventBridge ルールを使ったシンプルな仕組みで済むようになります。

関数ごとにデプロイのパイプラインが分かれていると、規模の拡張に比例して状態の追跡が難しくなることがありますが、この緩和策として今回のアップデートをお試しください。

この記事をシェアする

AWSのお困り事はクラスメソッドへ

関連記事